Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@internxt/sdk",
"author": "Internxt <hello@internxt.com>",
"version": "1.12.1",
"version": "1.12.2",
"description": "An sdk for interacting with Internxt's services",
"repository": {
"type": "git",
Expand Down
8 changes: 6 additions & 2 deletions src/shared/http/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> | undefined;

if (error.response) {
const response = error.response as AxiosResponse<{
Expand All @@ -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<string, string>;
} else if (error.request) {
errorMessage = 'Server unavailable';
errorStatus = 500;
Expand All @@ -220,7 +224,7 @@ export class HttpClient {
errorStatus = 400;
}

throw new AppError(errorMessage, errorStatus, errorCode);
throw new AppError(errorMessage, errorStatus, errorCode, errorHeaders);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/shared/types/errors.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
export default class AppError extends Error {
public readonly status?: number;
public readonly code?: string;
public readonly headers?: Record<string, string>;

constructor(message: string, status?: number, code?: string) {
constructor(message: string, status?: number, code?: string, headers?: Record<string, string>) {
super(message);

this.status = status;
this.code = code;
this.headers = headers;
}
}
Loading