mirror of
https://github.com/codex-team/codex.docs.git
synced 2025-08-06 14:05:22 +02:00
support for client, backend error tracking token
This commit is contained in:
parent
71de8d5ef8
commit
ac4feda9cb
1 changed files with 13 additions and 4 deletions
|
@ -14,9 +14,17 @@ dotenv.config();
|
|||
const app = express();
|
||||
const localConfig = rcParser.getConfiguration();
|
||||
|
||||
HawkCatcher.init(process.env.EXPRESS_NODEJS_HAWK_TOKEN || '');
|
||||
// Initialize the backend error tracking catcher.
|
||||
if (process.env.HAWK_TOKEN_BACKEND) {
|
||||
HawkCatcher.init(process.env.HAWK_TOKEN_BACKEND);
|
||||
}
|
||||
|
||||
app.locals.config = localConfig;
|
||||
// Set client error tracking token as app local.
|
||||
if (process.env.HAWK_TOKEN_CLIENT) {
|
||||
app.locals.config.hawkClientToken = process.env.HAWK_TOKEN_CLIENT;
|
||||
}
|
||||
|
||||
// view engine setup
|
||||
app.set('views', path.join(__dirname, './', 'views'));
|
||||
app.set('view engine', 'twig');
|
||||
|
@ -32,12 +40,13 @@ app.use('/uploads', express.static(config.get('uploads')));
|
|||
app.use('/', routes);
|
||||
|
||||
|
||||
// error handler
|
||||
// global error handler
|
||||
app.use(function (err: unknown, req: Request, res: Response, next: NextFunction) {
|
||||
// send error to hawk server.
|
||||
if (err instanceof Error) {
|
||||
// send any type of error to hawk server.
|
||||
if (process.env.HAWK_TOKEN_BACKEND && err instanceof Error) {
|
||||
HawkCatcher.send(err);
|
||||
}
|
||||
// only send Http based exception to client.
|
||||
if (err instanceof HttpException) {
|
||||
// set locals, only providing error in development
|
||||
res.locals.message = err.message;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue