Skip to content

Commit

Permalink
fix #133
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydaly committed Oct 29, 2019
1 parent 48d5718 commit 28c4acb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -26,7 +26,7 @@ class API {
this._callbackName = props && props.callback ? props.callback.trim() : 'callback'
this._mimeTypes = props && props.mimeTypes && typeof props.mimeTypes === 'object' ? props.mimeTypes : {}
this._serializer = props && props.serializer && typeof props.serializer === 'function' ? props.serializer : JSON.stringify
this._errorHeaderWhitelist = props && (props.errorHeaderWhitelist || []).map(header => header.toLowerCase())
this._errorHeaderWhitelist = props && Array.isArray(props.errorHeaderWhitelist) ? props.errorHeaderWhitelist.map(header => header.toLowerCase()) : []

// Set sampling info
this._sampleCounts = {}
Expand Down
16 changes: 16 additions & 0 deletions test/errorHandling.js
Expand Up @@ -10,6 +10,7 @@ const api3 = require('../index')({ version: 'v1.0' })
const api4 = require('../index')({ version: 'v1.0' })
const api5 = require('../index')({ version: 'v1.0', logger: { access: 'never' }})
const api_errors = require('../index')({ version: 'v1.0' })
const api6 = require('../index')() // no props

class CustomError extends Error {
constructor(message,code) {
Expand Down Expand Up @@ -172,6 +173,10 @@ api_errors.get('/responseError', (req,res) => {
res.redirect(310,'http://www.google.com')
})

api6.get('/testError', function(req,res) {
res.error('This is a test error message')
})


/******************************************************************************/
/*** BEGIN TESTS ***/
Expand Down Expand Up @@ -320,6 +325,17 @@ describe('Error Handling Tests:', function() {
expect(_log.msg).to.equal('This is a custom error')
}) // end it


it('Error, no props', async function() {
let _log
let _event = Object.assign({},event,{ path: '/testError'})
let logger = console.log
console.log = log => { try { _log = JSON.parse(log) } catch(e) { _log = log } }
let result = await new Promise(r => api6.run(_event,{},(e,res) => { r(res) }))
console.log = logger
expect(result).to.deep.equal({ multiValueHeaders: { 'content-type': ['application/json'] }, statusCode: 500, body: '{"error":"This is a test error message"}', isBase64Encoded: false })
}) // end it

})

}) // end ERROR HANDLING tests

0 comments on commit 28c4acb

Please sign in to comment.