feat: Send rest API errors to Sentry
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import logger from './logger.js';
|
import logger from './logger.js';
|
||||||
import objection from 'objection';
|
import objection from 'objection';
|
||||||
|
import * as Sentry from './sentry.ee.js';
|
||||||
const { NotFoundError, DataError } = objection;
|
const { NotFoundError, DataError } = objection;
|
||||||
|
|
||||||
// Do not remove `next` argument as the function signature will not fit for an error handler middleware
|
// Do not remove `next` argument as the function signature will not fit for an error handler middleware
|
||||||
@@ -17,8 +18,21 @@ const errorHandler = (error, request, response, next) => {
|
|||||||
response.status(400).end();
|
response.status(400).end();
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.error(error.message + '\n' + error.stack);
|
const statusCode = error.statusCode || 500;
|
||||||
response.status(error.statusCode || 500).end();
|
|
||||||
|
logger.error(request.method + ' ' + request.url + ' ' + statusCode);
|
||||||
|
logger.error(error.stack);
|
||||||
|
|
||||||
|
Sentry.captureException(error, {
|
||||||
|
tags: { rest: true },
|
||||||
|
extra: {
|
||||||
|
url: request?.url,
|
||||||
|
method: request?.method,
|
||||||
|
params: request?.params,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
response.status(statusCode).end();
|
||||||
};
|
};
|
||||||
|
|
||||||
const notFoundAppError = (error) => {
|
const notFoundAppError = (error) => {
|
||||||
|
Reference in New Issue
Block a user