diff --git a/package.json b/package.json index 5086bb9..f72ecf9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@internxt/sdk", "author": "Internxt ", - "version": "1.12.1", + "version": "1.12.2", "description": "An sdk for interacting with Internxt's services", "repository": { "type": "git", diff --git a/src/shared/http/client.ts b/src/shared/http/client.ts index bedc214..1931c25 100644 --- a/src/shared/http/client.ts +++ b/src/shared/http/client.ts @@ -197,7 +197,10 @@ export class HttpClient { * @private */ private normalizeError(error: AxiosError) { - let errorMessage: string, errorStatus: number, errorCode: string | undefined; + let errorMessage: string, + errorStatus: number, + errorCode: string | undefined, + errorHeaders: Record | undefined; if (error.response) { const response = error.response as AxiosResponse<{ @@ -212,6 +215,7 @@ export class HttpClient { errorMessage = response.data.message || response.data.error || JSON.stringify(response.data); errorStatus = response.status; errorCode = response.data.code; + errorHeaders = response.headers as Record; } else if (error.request) { errorMessage = 'Server unavailable'; errorStatus = 500; @@ -220,7 +224,7 @@ export class HttpClient { errorStatus = 400; } - throw new AppError(errorMessage, errorStatus, errorCode); + throw new AppError(errorMessage, errorStatus, errorCode, errorHeaders); } } diff --git a/src/shared/types/errors.ts b/src/shared/types/errors.ts index a67e1bb..a0d6524 100644 --- a/src/shared/types/errors.ts +++ b/src/shared/types/errors.ts @@ -1,11 +1,13 @@ export default class AppError extends Error { public readonly status?: number; public readonly code?: string; + public readonly headers?: Record; - constructor(message: string, status?: number, code?: string) { + constructor(message: string, status?: number, code?: string, headers?: Record) { super(message); this.status = status; this.code = code; + this.headers = headers; } }