(path, body, fallbackMessage)
| 1249 | return ` Try again in about ${rounded} second${rounded === 1 ? "" : "s"}.`; |
| 1250 | } |
| 1251 | |
| 1252 | const minutes = Math.max(1, Math.ceil(seconds / 60)); |
| 1253 | return ` Try again in about ${minutes} minute${minutes === 1 ? "" : "s"}.`; |
| 1254 | } |
| 1255 | |
| 1256 | async function postProtectedForm(path, body, fallbackMessage) { |
| 1257 | const response = await fetch(`${FORM_API_ORIGIN}${path}`, { |
| 1258 | method: "POST", |
| 1259 | headers: { |
| 1260 | Accept: "application/json", |
| 1261 | "Content-Type": "application/json", |
| 1262 | }, |
| 1263 | body: JSON.stringify(body), |
| 1264 | }); |
| 1265 | |
| 1266 | let responseBody = {}; |
| 1267 | try { |
| 1268 | responseBody = await response.json(); |
| 1269 | } catch { |
| 1270 | responseBody = {}; |
| 1271 | } |
| 1272 | |
| 1273 | if (!response.ok) { |
| 1274 | let message = responseBody.error || fallbackMessage; |
| 1275 | |
| 1276 | if (response.status === 429) { |
| 1277 | message += formatRetryHint(Number(response.headers.get("Retry-After"))); |
| 1278 | } |
| 1279 | |
| 1280 | throw new Error(message); |
no test coverage detected