Skip to content

Commit

Permalink
fix(request): handle 200 responses with an empty body (#381)
Browse files Browse the repository at this point in the history
Fixes #376
  • Loading branch information
silasbw committed Dec 24, 2018
1 parent ad561d0 commit 5672a3c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class Request {
return request(options, (err, res, body) => {
if (err) return cb(err)

if (isUpgradeRequired(body)) {
if (body && isUpgradeRequired(body)) {
return upgradeRequest(options, cb)
}

Expand Down
29 changes: 29 additions & 0 deletions test/request.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* eslint-env mocha */
'use strict'

const { expect } = require('chai')
const nock = require('nock')

const common = require('./common')
const Request = require('../lib/request')

const url = common.api.url

describe('lib.request', () => {
describe('Request', () => {
it('handles empty responses', done => {
nock(url)
.get('/foo')
.reply(200)

const backend = new Request({ url })
backend.http({
method: 'GET',
pathname: '/foo'
}).then(res => {
expect(res.body).to.be.an('undefined')
done()
})
})
})
})

0 comments on commit 5672a3c

Please sign in to comment.