Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Airbrake integration #231

Merged
merged 4 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/plugins/airbrake.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ const AirbrakePlugin = {
projectId: AirbrakeConfig.projectId,
projectKey: AirbrakeConfig.projectKey,
environment: AirbrakeConfig.environment,
performanceStats: false
errorNotifications: true,
performanceStats: false,
remoteConfig: false
})

// When Hapi emits a request event with an error we capture the details and use Airbrake to send a request to our
Expand Down
17 changes: 12 additions & 5 deletions app/plugins/error-pages.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,27 @@ const ErrorPagesPlugin = {
server.ext('onPreResponse', (request, h) => {
const { response } = request

// By adding `plugins: { errorPages: { plainOutput: true }}` to a route's `options:` property you can control
// whether we display our error handling pages or not. This is handy for API only where we would not want an
// error page to be returned as the response
const { errorPages: pluginSettings } = request.route.settings.plugins

// Whether we purposely return a Boom error in our controllers or not, exceptions thrown by the controllers are
// wrapped as Boom errors. So, in this context `isBoom` can be read as `isError`.
if (response.isBoom && !pluginSettings?.plainOutput) {
const { statusCode } = response.output

if (statusCode === 404) {
return h.view('404').code(statusCode)
}

server.logger.error({
statusCode,
message: response.message,
stack: response.data ? response.data.stack : response.stack
})
request.app.notifier.omfg(
response.message,
{
statusCode,
stack: response.data ? response.data.stack : response.stack
}
)

return h.view('500').code(statusCode)
}
Expand Down