Skip to content

Instantly share code, notes, and snippets.

@wbprice
Created March 17, 2017 18:56
Show Gist options
  • Save wbprice/d3e62904301b5e49bd0f8e94e0e2205e to your computer and use it in GitHub Desktop.
Save wbprice/d3e62904301b5e49bd0f8e94e0e2205e to your computer and use it in GitHub Desktop.
server.route({
method: 'POST',
path: settings.errorRoute,
handler: function handleRoute(request, reply) {
// We're only interested in handling application/json payloads.
if (request.mime !== 'application/json') {
return reply(boom.unsupportedMediaType());
}
return joi.validate(request && request.payload, internals.schema.payload, function(err) {
if (err) {
return reply(boom.badRequest(`${err.name}: {err.message}`));
}
let uuid = uuidLookup.read(request);
let sessionId = request.session && request.session.id;
// Log all the reports
request.payload.errorLogs.forEach(function(errorLog) {
// If the UUID and Session ID are available, add them to the log.
errorLog.uuid = uuid;
errorLog.sessionId = sessionId;
request.log('client error', jsesc(reduce(errorLog, function(memo, value, key) {
memo += `${key}='${value}'; `;
return memo;
}, '')));
});
return reply();
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment