Skip to content

Commit

Permalink
refactor: renames PassageError fields to be more aligned with the cli…
Browse files Browse the repository at this point in the history
…ent sdks
  • Loading branch information
ctran88 committed Apr 16, 2024
1 parent ee103c7 commit f88ec0f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/classes/PassageError.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
}

/**
Expand All @@ -44,8 +44,8 @@ export class PassageError extends Error {
public static async fromResponseError(message: string, err: ResponseError): Promise<PassageError> {
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,
});
}
Expand Down
8 changes: 4 additions & 4 deletions tests/PassageError.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

Expand All @@ -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();
});
});
Expand Down

0 comments on commit f88ec0f

Please sign in to comment.