Skip to content

Commit

Permalink
Raw error returned on onPreResponse event
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardo-veras committed Sep 29, 2021
1 parent e0352ff commit 9bde84d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,16 @@ server.on('onPostHandler', async payload => {
server.on('onPreResponse', async (response, event) => {
console.log('onPreResponse', event);
console.log('onPreResponse', response);

/*
response.error <default:null> v1.0.15+
In case the script fails, this field return the raw error object.
Good to create custom error messages on the response.
*/
if(response.error){
console.error(response.error);
}

});
```

Expand Down
5 changes: 4 additions & 1 deletion lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ exports = module.exports = class {
"content-type" : 'application/json'
};
this.body = { "statusCode": this.statusCode };
this.error = null;

const httpStatus = new HttpCodes();

Expand All @@ -37,6 +38,7 @@ exports = module.exports = class {
this.body.error = httpStatus[this.statusCode.toString()];
this.body.message = payload.message;
this.body.stack = payload.stack.toString().split('\n');
this.error = payload;
}

if(typeof payload=='string'){
Expand Down Expand Up @@ -77,7 +79,8 @@ exports = module.exports = class {
"body": JSON.stringify(Object.assign(
this.body,
payload.metas
))
)),
"error": this.error
};


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "serverless-aws-router",
"description": "Minimalist serverless router system for Node.JS",
"version": "1.0.14",
"version": "1.0.15",
"repository": "https://github.com/eduardo-veras/serverless-aws-router",
"main": "lib/index.js",
"engines": {
Expand Down

0 comments on commit 9bde84d

Please sign in to comment.