diff --git a/src/apns.ts b/src/apns.ts index 888b2bc..23b0671 100644 --- a/src/apns.ts +++ b/src/apns.ts @@ -113,9 +113,10 @@ export class ApnsClient extends EventEmitter { return notification } - const responseError = (await res.body.json()) as ApnsResponseError - - console.log({ responseError }) + const responseError = (await res.body.json().catch(() => ({ + reason: Errors.unknownError, + timestamp: Date.now(), + }))) as ApnsResponseError const error = new ApnsError({ statusCode: res.statusCode, diff --git a/test/apns2.test.ts b/test/apns2.test.ts index 5fc69ff..c9bc34d 100644 --- a/test/apns2.test.ts +++ b/test/apns2.test.ts @@ -111,9 +111,9 @@ describe("apns", () => { return promise }) - it("should fail to send a notification and emit an error", () => { + it("should fail to send a notification and emit a generic error", () => { const promise = new Promise((resolve) => { - apns.once(Errors.badDeviceToken, (err) => { + apns.once(Errors.error, (err) => { assert.equal(err.reason, Errors.badDeviceToken) resolve(null) })