From 7cce61b3bbab9655bdb57c163c2186e5410625c5 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Thu, 26 Oct 2017 15:19:10 +0200 Subject: [PATCH] Setup for sentry. Need to add __DSN__ value manually. --- seasoned_api/package.json | 3 ++- seasoned_api/src/webserver/app.js | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/seasoned_api/package.json b/seasoned_api/package.json index f65ac99..8ac0fe3 100644 --- a/seasoned_api/package.json +++ b/seasoned_api/package.json @@ -3,7 +3,7 @@ "main": "webserver/server.js", "scripts": { "start": "cross-env SEASONED_CONFIG=conf/development.json NODE_PATH=. node src/webserver/server.js", - "lint": "./node_modules/.bin/eslint src/webserver/" + "lint": "./node_modules/.bin/eslint src/webserver/" }, "dependencies": { "bcrypt-nodejs": "^0.0.3", @@ -17,6 +17,7 @@ "node-cache": "^4.1.1", "nodemailer": "^4.0.1", "python-shell": "^0.4.0", + "raven": "^2.2.1", "request": "^2.81.0", "request-promise": "^4.2", "sqlite": "^2.2.1", diff --git a/seasoned_api/src/webserver/app.js b/seasoned_api/src/webserver/app.js index 19bb4f1..58d7498 100644 --- a/seasoned_api/src/webserver/app.js +++ b/seasoned_api/src/webserver/app.js @@ -1,9 +1,12 @@ const express = require('express'); +const Raven = require('raven'); const bodyParser = require('body-parser'); const tokenToUser = require('./middleware/tokenToUser'); const mustBeAuthenticated = require('./middleware/mustBeAuthenticated'); +Raven.config('__DSN__').install(); const app = express(); // define our app using express +app.use(Raven.requestHandler()); // this will let us get the data from a POST // configure app to use bodyParser() app.use(bodyParser.json()); @@ -38,9 +41,15 @@ router.use((req, res, next) => { next(); }); -router.get('/', ((req, res) => { - res.json({ message: 'hooray! welcome to this api!' }); -})); +router.get('/', function mainHandler(req, res) { + throw new Error('Broke!'); +}); + +app.use(Raven.errorHandler()); +app.use(function onError(err, req, res, next) { + res.statusCode = 500; + res.end(res.sentry + '\n'); +}); /** * User