Permalink
Browse files

added default error on sendFile catch if not explicit

  • Loading branch information...
jeremydaly committed Apr 24, 2018
1 parent c88de6b commit dd147a3fa99c259b034478ae9a9b91c15df22263
Showing with 33 additions and 4 deletions.
  1. +4 −3 lib/response.js
  2. +29 −1 test/sendFile.js
@@ -308,6 +308,7 @@ class RESPONSE {
} catch(e) { // TODO: Add second catch?
// Execute callback with caught error
await fn(e)
this.error(e) // Throw error if not done in callback
}

} // end sendFile
@@ -353,7 +354,7 @@ class RESPONSE {

// Sends the request to the main callback
send(body) {

// Create the response
const response = {
headers: this._headers,
@@ -370,8 +371,8 @@ class RESPONSE {


// Trigger API error
error(err) {
this.app.catchErrors(err)
error(e) {
this.app.catchErrors(e)
} // end error

} // end Response class
@@ -48,7 +48,6 @@ api.get('/sendfile/err', function(req,res) {

api.get('/sendfile/test', function(req,res) {
res.sendFile('test/test.txt' + (req.query.test ? req.query.test : ''), err => {

// Return a promise
return Promise.try(() => {
for(let i = 0; i<40000000; i++) {}
@@ -66,6 +65,23 @@ api.get('/sendfile/test', function(req,res) {
})
})

api.get('/sendfile/error', function(req,res) {
res.sendFile('test/test.txtx', err => {

// Return a promise
return Promise.try(() => {
for(let i = 0; i<40000000; i++) {}
return true
}).then((x) => {
if (err) {
// log error
return true
}
})

})
})

api.get('/sendfile/buffer', function(req,res) {
res.sendFile(fs.readFileSync('test/test.txt'))
})
@@ -229,6 +245,18 @@ describe('SendFile Tests:', function() {



it('Text file error w/ callback override (promise - no end)', function() {
let _event = Object.assign({},event,{ path: '/sendfile/error', queryStringParameters: { test: 'x' } })

return new Promise((resolve,reject) => {
api.run(_event,{},function(err,res) { resolve(res) })
}).then((result) => {
expect(result).to.deep.equal({ headers: { 'content-type': 'application/json','x-error': 'true' }, statusCode: 500, body: result.body, isBase64Encoded: false })
})
}) // end it



it('Buffer Input', function() {
let _event = Object.assign({},event,{ path: '/sendfile/buffer' })

0 comments on commit dd147a3

Please sign in to comment.