diff --git a/src/classes/PassageError.ts b/src/classes/PassageError.ts index 735eef1..55bfdaf 100644 --- a/src/classes/PassageError.ts +++ b/src/classes/PassageError.ts @@ -1,13 +1,13 @@ import { ResponseError } from '../generated'; -type APIResponseError = { status: number; code: string; message: string }; +type APIResponseError = { statusCode: number; errorCode: string; message: string }; /** * PassageError Class used to handle errors from PassageFlex */ export class PassageError extends Error { - public readonly status: number | undefined; - public readonly code: string | undefined; + public readonly statusCode: number | undefined; + public readonly statusText: string | undefined; /** * Initialize a new PassageError instance. @@ -22,8 +22,8 @@ export class PassageError extends Error { } this.message = `${message}: ${response.message}`; - this.status = response.status; - this.code = response.code; + this.statusCode = response.statusCode; + this.statusText = response.errorCode; } /** @@ -44,8 +44,8 @@ export class PassageError extends Error { public static async fromResponseError(message: string, err: ResponseError): Promise { const body: { code: string; error: string } = await err.response.json(); return new PassageError(message, { - status: err.response.status, - code: body.code, + statusCode: err.response.status, + errorCode: body.code, message: body.error, }); } diff --git a/tests/PassageError.test.ts b/tests/PassageError.test.ts index 0d12fdd..13d939e 100644 --- a/tests/PassageError.test.ts +++ b/tests/PassageError.test.ts @@ -10,8 +10,8 @@ describe('PassageError', () => { expect(actual.message).toEqual(expected); expect(actual.stack).toBeDefined(); - expect(actual.code).toBeUndefined(); - expect(actual.status).toBeUndefined(); + expect(actual.statusText).toBeUndefined(); + expect(actual.statusCode).toBeUndefined(); }); }); @@ -37,8 +37,8 @@ describe('PassageError', () => { const actual = await PassageError.fromResponseError(expectedMessage, responseError); expect(actual.message).toEqual(`${expectedMessage}: ${expectedResponseError}`); - expect(actual.code).toEqual(expectedResponseCode); - expect(actual.status).toEqual(responseError.response.status); + expect(actual.statusText).toEqual(expectedResponseCode); + expect(actual.statusCode).toEqual(responseError.response.status); expect(actual.stack).toBeDefined(); }); });