Merge pull request #1363 from LittleUmbrella/master

add more detail to Generic Error message for easier troubleshooting
This commit is contained in:
Ferdi Koomen 2023-04-11 09:04:31 +02:00 committed by GitHub
commit 280e96f38a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,6 +16,16 @@ export const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult):
}
if (!result.ok) {
throw new ApiError(options, result, 'Generic Error');
const resultBody = (() => {
try {
return JSON.stringify(result.body, null, 2);
} catch (err) {
return undefined;
}
})();
throw new ApiError(
result,
`Generic Error: status: ${result.status ?? 'unknown'}; status text: ${result.statusText}; body: ${resultBody}`
);
}
};