Skip to content

Commit

Permalink
Merge pull request #553 from hearchco/as/fix/fetchresults
Browse files Browse the repository at this point in the history
fix(featchresults): better error throw when parsing JSON
  • Loading branch information
aleksasiriski authored Oct 15, 2024
2 parents 91b5b27 + 5c7800a commit ebf7be0
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/lib/functions/api/fetchresults.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,22 @@ export async function fetchResults(params, fetcher = fetch) {
try {
jsonResponse = await response.json();
} catch (/** @type {any} */ err) {
/** @type {string} */
let textResponse;
try {
textResponse = await response.text();
} catch (/** @type {any} */ err) {
// Internal Server Error.
throw error(
500,
`Failed to read response text: ${err.message} (${response.status} ${response.statusText})`
);
}
// Internal Server Error.
throw error(500, `Failed to parse results: ${err.message}`);
throw error(
500,
`Failed to parse results: ${err.message} (${response.status} ${response.statusText}): ${textResponse}`
);
}

if ('message' in jsonResponse && 'value' in jsonResponse) {
Expand Down

0 comments on commit ebf7be0

Please sign in to comment.