gildas-lormeau/SingleFile · error · Error
await response.text()
Error message
await response.text()
What it means
upload() in the REST form API treats only HTTP 200/201/202 as success; for any other status it throws an Error whose message is the raw response body text (await response.text()). The message you see is literally whatever error payload the server returned, so the server's response text is the diagnostic.
Source
Thrown at src/lib/rest-form-api/index.js:65
this.controller = new AbortController();
const blob = content instanceof Blob ? content : new Blob([content], { type: "text/html" });
let formData = new FormData();
if (this.fileFieldName) {
formData.append(this.fileFieldName, blob, filename);
}
if (this.urlFieldName) {
formData.append(this.urlFieldName, url);
}
const response = await fetch(this.restApiUrl, {
method: "POST",
body: formData,
headers: this.headers,
signal: this.controller.signal
});
if ([200, 201, 202].includes(response.status)) {
return response.json();
} else {
throw new Error(await response.text());
}
}
abort() {
if (this.controller) {
this.controller.abort();
}
}
}
View on GitHub (pinned to 517fb7c5cf)
Solutions
- Log the full thrown message (response text) — it contains the server's error description; fix the root cause it names
- Check the endpoint URL, HTTP method and multipart field names against the API docs
- Verify auth headers/token validity and the request's Content-Type/boundary
- Add handling for rate limits (429) and large files (413), with retry/backoff for 5xx
Example fix
// before
} else {
throw new Error(await response.text());
}
// after
} else {
const body = await response.text();
const err = new Error(`Upload failed (${response.status}): ${body}`);
err.status = response.status;
throw err;
} Defensive patterns
Strategy: try-catch
Validate before calling
if (!file || file.size > MAX_UPLOAD_BYTES) throw new Error(`File too large: ${file && file.size} bytes`);
if (!this.headers.Authorization) throw new Error("Missing auth token for form API upload"); Type guard
function isUploadSuccess(res) { return [200, 201, 202].includes(res && res.status); } Try / catch
try {
await api.upload(file);
} catch (e) {
const status = extractStatus(e); // parse from server text or track separately
if (status === 429 || status >= 500) await retryWithBackoff(() => api.upload(file));
else if (status === 401) await reauthenticate();
else throw e;
} Prevention
- Include response.status in thrown errors for programmatic handling
- Check token validity/expiry before uploads
- Enforce client-side file size limits matching server limits
- Verify endpoint URL per environment (staging vs prod)
When it happens
Trigger: Uploading a file when the server responds 400 (invalid form fields/boundary), 401/403 (bad credentials), 404 (wrong endpoint URL), 413 (file too large), or 5xx — anything outside [200,201,202].
Common situations: Expired or missing auth token; API endpoint path changed or is environment-specific; upload exceeding server max body size; malformed multipart form construction; server temporarily down.
Understand the failure class
Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.
Related errors
- error.message + " (RestFormApi)"
- unknown_error (" + httpFinishResponse.status + ")
- response.statusText || "Error " + response.status
- Error " + response.status
- error.message + " (GitHub)"
AI-assisted analysis of gildas-lormeau/SingleFile@517fb7c5cf (2026-09-01).
Data as JSON: /api/errors/0ff6e040703f52c2.
Report an issue: GitHub.