MCPcopy Create free account
hub / github.com/Forward-Future/loopy / postProtectedForm

Function postProtectedForm

loop-library/site/script.js:1251–1277  ·  view source on GitHub ↗
(path, body, fallbackMessage)

Source from the content-addressed store, hash-verified

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
1256async 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);

Callers 1

script.jsFile · 0.85

Calls 3

formatRetryHintFunction · 0.85
fetchFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected