Skip to content
Permalink
Browse files

fix #133

  • Loading branch information
jeremydaly committed Oct 29, 2019
1 parent 48d5718 commit 28c4acbb93e1c0000b4992d80603cafba537cb14
Showing with 17 additions and 1 deletion.
  1. +1 −1 index.js
  2. +16 −0 test/errorHandling.js
@@ -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 = {}
@@ -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) {
@@ -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 ***/
@@ -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.
You can’t perform that action at this time.