Skip to content

Commit

Permalink
Update error
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewBarba committed Nov 16, 2024
1 parent a70e040 commit 5c450da
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/apns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions test/apns2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down

0 comments on commit 5c450da

Please sign in to comment.