mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 11:57:08 +00:00
Instrument alerts for HTTP backend.
An alert is sent whenever an endpoint returns
an error other than an explicit failure (e.g.,
it won't send an alert if a middleware intentionally
returns a {status: XXX} object).
This commit is contained in:
@@ -3,6 +3,7 @@ const http = require('http');
|
||||
const express = require('express');
|
||||
const cookieParser = require('cookie-parser')
|
||||
|
||||
const maybeSendAlert = require("../lib/alerts");
|
||||
const mw = require('./middleware');
|
||||
|
||||
const app = express();
|
||||
@@ -153,14 +154,25 @@ app.map({
|
||||
// Generic error handler. Stops stack dumps
|
||||
// being sent to clients.
|
||||
app.use(function (err, req, res, next) {
|
||||
const title = `HTTP backend error at ${req.method} ${req.originalUrl}`;
|
||||
const description = err.message;
|
||||
const message = err.message;
|
||||
const alert = {title, message, description, error: err};
|
||||
|
||||
console.log("Error:", err);
|
||||
|
||||
if (err instanceof Error && err.name != "UnauthorizedError") {
|
||||
console.error(err.stack);
|
||||
res.status(500).send('General internal error');
|
||||
maybeSendAlert(alert);
|
||||
} else if (typeof err === 'string') {
|
||||
res.status(500).send({message: err});
|
||||
maybeSendAlert(alert);
|
||||
} else {
|
||||
res.status(err.status || 500).send({message: err.message || (err.inner && err.inner.message) || "Internal error"});
|
||||
if (!res.status) {
|
||||
maybeSendAlert(alert);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user