Skip to content

Commit

Permalink
fix: unexpected errors (#34)
Browse files Browse the repository at this point in the history
* fix: unexpected errors

* fix: test provoking error

* chore: bump version to 0.1.1
  • Loading branch information
DanielRamosAcosta authored Jul 12, 2021
1 parent 69fd1c1 commit 8e08ec0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@acid-tango/arcus-js",
"version": "0.1.0",
"version": "0.1.1",
"description": "",
"author": "",
"license": "MIT",
Expand Down
18 changes: 17 additions & 1 deletion src/Arcus.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NETFLIX, TELCEL, TOTALPLAY, TRANSACTION } from '../test/fixtures/fixtures';
import { Arcus } from './Arcus';
import { ArcusBiller } from './typings/ArcusBiller';
import { ArcusErrorCode } from './typings/ArcusErrorCode';

const billerWithName = (name: string) => (utility: ArcusBiller) => utility.name === name;

Expand Down Expand Up @@ -133,5 +134,20 @@ describe('Arcus', () => {

it.todo('deleteBill');

it.todo('singlePay');
describe('singlePay', () => {
// At the time of this test, this biller was failing because a 504, now it's working
it.skip('does not fail when buying a top up', async () => {
const error = await arcus
.singlePay({
billerId: 13597,
accountNumber: '4545454545',
currency: 'MXN',
amount: 10,
externalId: 'db8bf3b9-6db5-410f-ac5f-e0967eac5ff9',
})
.catch((error) => error);

expect(error.code).toEqual(ArcusErrorCode.UNEXPECTED_ERROR);
});
});
});
13 changes: 13 additions & 0 deletions src/Arcus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ export class Arcus {
}

private static async dealWithErrors(response: Response) {
/**
* If status is greater than 500, Arcus is returning and HTML response, so we can't treat the
* body as JSON
*/
if (response.status >= 500) {
const text = await response.text();

throw new ArcusError(
ArcusErrorCode.UNEXPECTED_ERROR,
text || `Unknown error from Arcus: ${response.status}`,
);
}

if (response.status >= 400) {
const body: ArcusErrorResponse | undefined = await response.json();

Expand Down

0 comments on commit 8e08ec0

Please sign in to comment.