Eyewitness provides a few usage and configuration options, which developers can modify as per their need. Below you will see how each option works out.
As we mentioned before, eyewitness's main job is to report unwanted exceptions directly to your inbox. But there are (and will be) cases where you may want to also inform some system (like Microsoft Teams, Slack, or any error logging system etc) about the exception.
We provide webhook options, where developers can easily setup their webhooks while configuring the modules, and eyewitness along with sending mail, will also send the complete report to yur specified endpoints.
Notice the highlighted webhooks array, url, method, header are the options, you need to pass to the object.
Incase any exception happens on your system, you will receive following payload as request on your webhook.
{
"exception":{
"name":"BadGatewayException",
"message":"Oops! This should'nt have happened",
"stack":"Error: Oops! This should'nt have happened\n at AppController.getHello (/Users/vinayaksarawagi/Sites/eyewitness-test/dist/main.js:194:15)\n at /Users/vinayaksarawagi/Sites/eyewitness-test/node_modules/@nestjs/core/router/router-execution-context.js:38:29\n at InterceptorsConsumer.intercept (/Users/vinayaksarawagi/Sites/eyewitness-test/node_modules/@nestjs/core/interceptors/interceptors-consumer.js:11:20)\n at /Users/vinayaksarawagi/Sites/eyewitness-test/node_modules/@nestjs/core/router/router-execution-context.js:46:60\n at /Users/vinayaksarawagi/Sites/eyewitness-test/node_modules/@nestjs/core/router/router-proxy.js:9:23\n at Layer.handle [as handle_request] (/Users/vinayaksarawagi/Sites/eyewitness-test/node_modules/express/lib/router/layer.js:95:5)\n at next (/Users/vinayaksarawagi/Sites/eyewitness-test/node_modules/express/lib/router/route.js:137:13)\n at Route.dispatch (/Users/vinayaksarawagi/Sites/eyewitness-test/node_modules/express/lib/router/route.js:112:3)\n at Layer.handle [as handle_request] (/Users/vinayaksarawagi/Sites/eyewitness-test/node_modules/express/lib/router/layer.js:95:5)\n at /Users/vinayaksarawagi/Sites/eyewitness-test/node_modules/express/lib/router/index.js:281:22"
},
"request":{
"timestamp":"Fri Oct 09 2020 01:04:38 GMT+0530 (India Standard Time)",
"headers":"{\"host\":\"localhost:3000\",\"connection\":\"keep-alive\",\"upgrade-insecure-requests\":\"1\",\"user-agent\":\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36\",\"accept\":\"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\",\"sec-fetch-site\":\"none\",\"sec-fetch-mode\":\"navigate\",\"sec-fetch-user\":\"?1\",\"sec-fetch-dest\":\"document\",\"accept-encoding\":\"gzip, deflate, br\",\"accept-language\":\"en-GB,en-US;q=0.9,en;q=0.8\"}",
"payload":"{}",
"url":"http://localhost:3000/"
}
}
Extra Bonus
Incase, you want to send custom request objects, we provide a requestBuilder property, which expects a function. Below is an example on how you can use it.
extra:'Built using custom `requestBuilder` method',
}),
},
],
}),
],
controllers:[],
providers:[],
})
exportclassAppModule{}
We have configured our custom payload requestBuilder method, now whenever any exception is witnessed on your server, you will receive following payload:
{
"message":"Oops! This should'nt have happened",
"extra":"Built using custom `requestBuilder` method"