Skip to content

Commit

Permalink
Merge pull request #23 from Nordstrom/bug/22-response-body-error
Browse files Browse the repository at this point in the history
Fix issue #22
  • Loading branch information
tmwllc authored Sep 1, 2017
2 parents b330e0b + 517b287 commit c782350
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/middleware/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const _global = {
}

function handleResponse (span, status, err, msg) {
if (err || status >= 400) {
if (err instanceof Error || status >= 400) {
// Error detected. Mark error, status code, and log error event
span.setTag('error', true)
if (status) span.setTag('http.status_code', status)
Expand Down
11 changes: 11 additions & 0 deletions test/request.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ function createServer () {
req.on('end', () => {
let path = urlParse(req.url).pathname
let status = Number(path.split('?')[0].split('/')[1])
if (req.headers && req.headers['content-type'] === 'application/json'){
b = JSON.parse(b)
}
switch (status) {
case 301:
res.writeHead(301, { Location: '/200' })
Expand Down Expand Up @@ -146,6 +149,14 @@ describe('request', () => {
})
})

it('should not mark error on 200', () => {
return tr({ method: 'PUT', uri: `${s.url}/200`, json: true, body: {data: 'test data'} })
.then(() => {
let rec = JSON.parse(buf[0])
rec.tags.should.not.have.property('error')
})
})

it('should mark http.status_code on 400', () => {
return tr({ method: 'GET', uri: `${s.url}/400`, json: true })
.catch(() => {
Expand Down

0 comments on commit c782350

Please sign in to comment.