diff --git a/package.json b/package.json index 25152ab..5ae4f76 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@acid-tango/arcus-js", - "version": "0.1.0", + "version": "0.1.1", "description": "", "author": "", "license": "MIT", diff --git a/src/Arcus.spec.ts b/src/Arcus.spec.ts index 651c4d3..8bbd20f 100644 --- a/src/Arcus.spec.ts +++ b/src/Arcus.spec.ts @@ -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; @@ -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); + }); + }); }); diff --git a/src/Arcus.ts b/src/Arcus.ts index 76e636c..0698b86 100644 --- a/src/Arcus.ts +++ b/src/Arcus.ts @@ -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();