mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
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:
parent
8a1e04f203
commit
371aba1639
@ -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}`
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user