This repository has been archived by the owner on Apr 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(logs): log endpoint errors for better debugging (#1627) r=vbudhr…
…am,philbooth New "server.EndpointError" error logging...
- Loading branch information
Showing
2 changed files
with
95 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
'use strict' | ||
|
||
const assert = require('insist') | ||
const server = require('../../lib/server') | ||
|
||
describe('lib/server', () => { | ||
describe('trimLocale', () => { | ||
it('trims given locale', () => { | ||
assert.equal(server._trimLocale(' fr-CH, fr;q=0.9 '), 'fr-CH, fr;q=0.9') | ||
}) | ||
}) | ||
|
||
describe('logEndpointErrors', () => { | ||
let msg = 'Timeout' | ||
let reason = 'Socket fail' | ||
let response = { | ||
__proto__: { | ||
name: 'EndpointError' | ||
}, | ||
message: msg, | ||
reason: reason | ||
} | ||
|
||
it('logs an endpoint error', (done) => { | ||
const mockLog = { | ||
error: (err) => { | ||
assert.equal(err.op, 'server.EndpointError') | ||
assert.equal(err.message, msg) | ||
assert.equal(err.reason, reason) | ||
done() | ||
} | ||
} | ||
assert.equal(server._logEndpointErrors(response, mockLog)) | ||
}) | ||
|
||
it('logs an endpoint error with a method', (done) => { | ||
response.attempt = { | ||
method: 'PUT' | ||
} | ||
|
||
const mockLog = { | ||
error: (err) => { | ||
assert.equal(err.op, 'server.EndpointError') | ||
assert.equal(err.message, msg) | ||
assert.equal(err.reason, reason) | ||
assert.equal(err.method, 'PUT') | ||
done() | ||
} | ||
} | ||
assert.equal(server._logEndpointErrors(response, mockLog)) | ||
}) | ||
}) | ||
}) |