diff --git a/src/frontend/apps/desk/src/api/APIError.ts b/src/frontend/apps/desk/src/api/APIError.ts index a94adb4..2aaf715 100644 --- a/src/frontend/apps/desk/src/api/APIError.ts +++ b/src/frontend/apps/desk/src/api/APIError.ts @@ -1,17 +1,20 @@ -interface IAPIError { +interface IAPIError { status: number; cause?: string[]; + data?: T; } -export class APIError extends Error implements IAPIError { - public status: number; - public cause?: string[]; +export class APIError extends Error implements IAPIError { + public status: IAPIError['status']; + public cause?: IAPIError['cause']; + public data?: IAPIError['data']; - constructor(message: string, { status, cause }: IAPIError) { + constructor(message: string, { status, cause, data }: IAPIError) { super(message); this.name = 'APIError'; this.status = status; this.cause = cause; + this.data = data; } } diff --git a/src/frontend/apps/desk/src/api/utils.ts b/src/frontend/apps/desk/src/api/utils.ts index 6be3c02..5a4370e 100644 --- a/src/frontend/apps/desk/src/api/utils.ts +++ b/src/frontend/apps/desk/src/api/utils.ts @@ -1,4 +1,4 @@ -export const errorCauses = async (response: Response) => { +export const errorCauses = async (response: Response, data?: unknown) => { const errorsBody = (await response.json()) as Record< string, string | string[] @@ -13,5 +13,6 @@ export const errorCauses = async (response: Response) => { return { status: response.status, cause: causes, + data, }; };