diff --git a/packages/share/src/reviewVersionSentences.mjs b/packages/share/src/reviewVersionSentences.mjs index 20572da0c9..96c42fd65b 100644 --- a/packages/share/src/reviewVersionSentences.mjs +++ b/packages/share/src/reviewVersionSentences.mjs @@ -11,8 +11,10 @@ const SAID = { export_too_large: "This video is over 2 GB, the most a review page takes. Export a smaller one.", export_too_long: "This video is over 30 minutes, the most a review page takes. Export a shorter one.", + export_hourly_limit: (error) => + `You've added the most versions for this hour. Try again ${laterIn(error.retryAfterMs, "in an hour")}.`, export_daily_limit: (error) => - `You've added the most versions for today. Try again ${laterIn(error.retryAfterMs)}.`, + `You've added the most versions for today. Try again ${laterIn(error.retryAfterMs, "tomorrow")}.`, content_rejected: "This video can't be shared.", export_blocked: "Adding videos to review pages isn't available for this account.", feature_unavailable: "Review pages aren't available for your account yet.", @@ -38,9 +40,9 @@ export function versionSentence(error, fallback = "Couldn't add this version. Tr return fallback; } -/** "in about 3 hours", from the server's Retry-After. @param {number | undefined} ms */ -function laterIn(ms) { - if (!ms) return "tomorrow"; +/** "in about 3 hours", from the server's Retry-After; `unknown` when it sent none. @param {number | undefined} ms @param {string} unknown */ +function laterIn(ms, unknown) { + if (!ms) return unknown; const minutes = Math.ceil(ms / 60_000); if (minutes < 60) return `in ${minutes} minute${minutes === 1 ? "" : "s"}`; const hours = Math.round(minutes / 60); diff --git a/packages/share/tests/reviewVersionSentences.test.mjs b/packages/share/tests/reviewVersionSentences.test.mjs new file mode 100644 index 0000000000..81c296d882 --- /dev/null +++ b/packages/share/tests/reviewVersionSentences.test.mjs @@ -0,0 +1,29 @@ +import assert from "node:assert/strict"; +import { test } from "node:test"; +import { ReviewFailed } from "../src/reviewClient.mjs"; +import { versionSentence } from "../src/reviewVersionSentences.mjs"; + +test("the hourly version cap says how long to wait instead of telling the person to try again now", () => { + assert.equal( + versionSentence(new ReviewFailed(429, "export_hourly_limit", undefined, 25 * 60_000)), + "You've added the most versions for this hour. Try again in 25 minutes.", + ); +}); + +test("each cap falls back to its own window when the server sends no Retry-After", () => { + assert.equal( + versionSentence(new ReviewFailed(429, "export_hourly_limit")), + "You've added the most versions for this hour. Try again in an hour.", + ); + assert.equal( + versionSentence(new ReviewFailed(429, "export_daily_limit")), + "You've added the most versions for today. Try again tomorrow.", + ); +}); + +test("the daily version cap rounds a long wait to hours", () => { + assert.equal( + versionSentence(new ReviewFailed(429, "export_daily_limit", undefined, 2 * 60 * 60_000)), + "You've added the most versions for today. Try again in about 2 hours.", + ); +});