mapbox / mapbox/pagerduty

401 errors for get requests cause a stack trace

Open
#8 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7
Forks
3
PR merge metrics
No merged PRs in 30d

Description

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.

```JS
[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. (/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. (/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?

Contributor guide

Open the contributing guide

Research direction

Start with index.js lines 50-51 and reproduce a GET using an expired auth token that returns a 401 without a JSON body. Verify that this path no longer produces a stack trace and instead reports the authentication failure appropriately.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.