Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Commit

Permalink
Rollbar ignores 4xx errors
Browse files Browse the repository at this point in the history
Fixes rb#99, #135
  • Loading branch information
saiichihashimoto committed Jun 14, 2016
1 parent d595c55 commit fd3448a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
8 changes: 6 additions & 2 deletions application/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ app.get(/^(?!\/(?:(?:api|svg)\/|png|zip))[^.]*$/, function(req, res, next) {
return res.redirect(302, response[0].pathname + response[0].search);
}
if (!response[1]) {
return res.status(404).send('Not Found');
var err = new Error();
err.status = 404;
return next(err);
}

var store = Store();
Expand All @@ -94,7 +96,9 @@ app.get(/^(?!\/(?:(?:api|svg)\/|png|zip))[^.]*$/, function(req, res, next) {
console.timeEnd('time_' + i);
}
if (!html) {
return res.status(404).send('Not Found');
var err = new Error();
err.status = 404;
return next(err);
}
res.set('Cache-Control', 'public, max-age=' + (24 * 60 * 60));
res.set('Last-Modified', (new Date()).toUTCString());
Expand Down
32 changes: 22 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ require('babel-register');
var _ = require('underscore');
var feathers = require('feathers');
var fs = require('fs');
var http = require('http');
var logos = require('instant-logos');
var os = require('os');
var path = require('path');
Expand All @@ -25,6 +26,14 @@ var search = require('./search');
var Logos = require('./services/Logos');
var Suggestions = require('./services/Suggestions');

var rollbarErrorHandler = (process.env.NODE_ENV && process.env.ROLLBAR_ACCESS_TOKEN) ?
rollbar.errorHandler(process.env.ROLLBAR_ACCESS_TOKEN || ' ', rollbar.config) :
function(err, req, res, next) {
console.error(err);
console.error(err.stack);
next(err);
};

_.chain(logos)
.reject(function(logo) {
return !logo.svg || !logo.svg.path;
Expand Down Expand Up @@ -161,23 +170,26 @@ app.get('/api/logo_suggestions', function(req, res, next) {
);
});

app.all('*', function(req, res) {
res.status(404).send('Not Found');
app.all('*', function(req, res, next) {
var err = new Error();
err.status = 404;
next(err);
});

app.use((process.env.NODE_ENV && process.env.ROLLBAR_ACCESS_TOKEN) ?
rollbar.errorHandler(process.env.ROLLBAR_ACCESS_TOKEN || ' ', rollbar.config) :
function(err, req, res, next) {
console.error(err);
console.error(err.stack);
next(err);
});
app.use(function(err, req, res, next) {
var status = err.status || err.code || 500;
if (status >= 400 && status < 500) {
return next(err);
}
rollbarErrorHandler(err, req, res, next);
});

app.use(function(err, req, res, next) {
if (res.headersSent) {
return next(err);
}
res.status(500).send(err.message);
var status = err.status || err.code || 500;
res.status(status).send(err.message || http.STATUS_CODES[status]);
});

app.listen(app.get('port'), function() {
Expand Down

0 comments on commit fd3448a

Please sign in to comment.