Skip to content

401 errors for get requests cause a stack trace #8

@daniel-beard

Description

@daniel-beard

The following code here: https://github.com/mapbox/pagerduty/blob/master/index.js#L50-L51
Assumes that there will always be a JSON response body. But with an expired auth token, you instead get a stack trace because the response isn't a JSON object.

E.g.

[Mon Dec 03 2018 13:47:45 GMT-0800 (PST)] ERROR TypeError: Cannot read property 'errors' of undefined
    at Request.request [as _callback] (/Users/dbeard/Dev/iosbot/iosbot/node_modules/@mapbox/pagerduty/index.js:51:107)
    at Request.self.callback (/Users/dbeard/Dev/iosbot/iosbot/node_modules/request/request.js:186:22)
    at emitTwo (events.js:126:13)
    at Request.emit (events.js:214:7)
    at Request.<anonymous> (/Users/dbeard/Dev/iosbot/iosbot/node_modules/request/request.js:1163:10)
    at emitOne (events.js:116:13)
    at Request.emit (events.js:211:7)
    at IncomingMessage.<anonymous> (/Users/dbeard/Dev/iosbot/iosbot/node_modules/request/request.js:1085:12)
    at Object.onceWrapper (events.js:313:30)
    at emitNone (events.js:111:20)
    at IncomingMessage.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:139:11)
    at process._tickCallback (internal/process/next_tick.js:181:9)

Perhaps a message specifically calling out 401 issues would be better?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions