add more detail to Generic Error message for easier troubleshooting. 'Generic Error' gives no insight into the nature of the issue, whereas having at least the http status conveys a great deal for troubleshooting

This commit is contained in:
Toby Farris 2022-12-13 13:08:19 -08:00
parent 8a1e04f203
commit 371aba1639

View File

@ -16,6 +16,16 @@ const catchErrorCodes = (options: ApiRequestOptions, result: ApiResult): void =>
}
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}`
);
}
};