Skip to content

Commit 9fbdab7

Browse files
committed
Fixed error message extraction
1 parent aa93520 commit 9fbdab7

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

errors/DefaultErrorHandler.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ErrorHandler, HttpError, BadRequestError, AuthenticationError, Authoriz
22
import { HttpStatusCode, HttpHeader } from "../http";
33

44
/**
5-
* Handles errors in HTTP responses by mapping status codes to common exception types.
5+
* Handles errors in HTTP responses by mapping status codes to common error types.
66
*/
77
export class DefaultErrorHandler implements ErrorHandler {
88
/**
@@ -29,8 +29,9 @@ export class DefaultErrorHandler implements ErrorHandler {
2929

3030
private async extractJsonMessage(response: Response) {
3131
const contentType = response.headers.get(HttpHeader.ContentType);
32-
if (contentType?.startsWith("application/json") || contentType?.includes("+json"))
33-
return (await response.json())?.body;
32+
return (contentType?.startsWith("application/json") || contentType?.includes("+json"))
33+
? (await response.json())?.message
34+
: undefined;
3435
}
3536

3637
private static mapToError(status: HttpStatusCode, message: string) {

0 commit comments

Comments
 (0)