Created
September 21, 2017 03:54
-
-
Save chrisjensen/75d93f09fb982dc7767ec18d93c88efb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const SENTRY_ID = ''; | |
const SENTRY_KEY = ''; | |
const SENTRY_APP = ''; | |
const PORT = 3000; | |
const app = require('koa')(); | |
const Router = require('koa-router'); | |
// Configure Sentry | |
const Raven = require('raven'); | |
const sentryUrl = `https://${SENTRY_ID}:${SENTRY_KEY}@sentry.io/${SENTRY_APP}`; | |
Raven.config(sentryUrl).install(); | |
function* errors(next) { | |
let err; | |
try { | |
yield next; | |
} catch (e) { | |
err = e; | |
this.body = { message: err.message }; | |
} finally { | |
Raven.captureException( | |
err, | |
{ | |
// req: this.request, | |
// request: this.request, | |
// request: this.req, | |
req: this.req, | |
}, | |
(sendErr, eventId) => { | |
if (sendErr) { | |
console.error('Failed to send captured exception to Sentry', err); | |
} | |
} | |
); | |
} | |
} | |
app.use(errors); | |
// Routes | |
const api = new Router(); | |
api.get('/', function* show() { this.body = { message: 'Demo running' }; }); | |
api.post('/error', function* makeError() { throw new Error('Testing sentry: req: this.req'); }); | |
app.use(api.middleware()); | |
app.listen(PORT); | |
console.log(`Server listening on port: ${PORT}`); | |
module.exports = app; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment