Tries to fix some errors

parent 72b8ce52
......@@ -8,7 +8,6 @@ import * as path from 'path';
import { RoutingControllersOptions, useExpressServer } from 'routing-controllers';
import * as swaggerUi from 'swagger-ui-express';
import options from './lib/cors.config';
import { IGlobal } from './main';
import { roleAuthorizationChecker } from './routers/middleware/roleAuthorizationChecker';
import { dynamicStatistics, staticStatistics } from './statistics';
......@@ -24,7 +23,7 @@ export const routingControllerOptions: RoutingControllersOptions = {
},
},
authorizationChecker: roleAuthorizationChecker,
defaultErrorHandler: true,
defaultErrorHandler: false,
cors: options,
controllers: [path.join(__dirname, 'routers', '/rest/*.js')],
middlewares: [path.join(__dirname, 'routers', '/middleware/*.js')],
......@@ -77,13 +76,6 @@ class App {
});
this._express.use(`${staticStatistics.routePrefix}/`, router);
this._express.use((err, req, res, next) => {
if (process.env.NODE_ENV === 'production') {
(<IGlobal>global).createDump(err);
}
next();
});
}
}
......
import { IGlobal } from '../main';
import LoggerService from '../services/LoggerService';
export function rejectionToCreateDump(reason): void {
try {
(<IGlobal>global).createDump(reason);
} catch (e) {
LoggerService.error('Cannot create dump', e.message);
} finally {
console.error(reason.stack || reason.message || reason);
}
}
......@@ -18,6 +18,7 @@ import MemberDAO from './db/MemberDAO';
import QuizDAO from './db/quiz/QuizDAO';
import UserDAO from './db/UserDAO';
import { jsonCensor } from './lib/jsonCensor';
import { rejectionToCreateDump } from './lib/rejectionToCreateDump';
import { WebSocketRouter } from './routers/websocket/WebSocketRouter';
import LoggerService from './services/LoggerService';
import { staticStatistics } from './statistics';
......@@ -47,20 +48,10 @@ interface IInetAddress {
address: string;
}
function rejectionToCreateDump(reason): void {
try {
(<IGlobal>global).createDump(reason);
} catch (e) {
LoggerService.error('Cannot create dump', e.message);
} finally {
// noinspection TsLint
console.trace(reason);
}
}
process.on('unhandledRejection', rejectionToCreateDump);
process.on('uncaughtException', rejectionToCreateDump); // Throws exceptions when debugging with IntelliJ
if (process.env.NODE_ENV === 'production') {
process.on('unhandledRejection', rejectionToCreateDump);
process.on('uncaughtException', rejectionToCreateDump); // Throws exceptions when debugging with IntelliJ
}
(<IGlobal>global).DAO = {
......
import * as express from 'express';
import { ExpressErrorMiddlewareInterface, HttpError, Middleware } from 'routing-controllers';
@Middleware({ type: 'after' })
export class ErrorHandlerMiddleware implements ExpressErrorMiddlewareInterface {
constructor() { }
public error(error: HttpError, req: express.Request, res: express.Response, next: express.NextFunction): void {
// It seems like some decorators handle setting the response (i.e. class-validators)
if (!res.headersSent) {
res.status(error.httpCode || 500);
res.json({
name: error.name,
message: error.message,
errors: error['errors'] || [],
});
}
console.error(error.stack);
}
}
......@@ -351,13 +351,14 @@ export class LibRouter extends AbstractRouter {
return new Promise<object>(resolve => {
mathjaxArray.forEach(async (mathjaxPlain, index) => {
const dbResult = MathjaxDAO.getAllPreviouslyRenderedData(mathjaxPlain);
const dbResult = MathjaxDAO.getAllPreviouslyRenderedData(mathjaxPlain);
if (dbResult) {
result.push(dbResult);
return;
}
} else {
try {
const data = await mjAPI.typeset({
math: mathjaxPlain.replace(/( ?\${1,2} ?)/g, ''),
format: format,
......@@ -365,10 +366,12 @@ export class LibRouter extends AbstractRouter {
css: output === 'html',
svg: output === 'svg',
mml: output === 'mml',
}).catch(err => console.log(err));
});
MathjaxDAO.updateRenderedData(data, mathjaxPlain);
result.push(data);
} catch (e) {
console.error('error while trying to parse mathjax', e);
}
if (index === mathjaxArray.length - 1) {
......
......@@ -137,7 +137,7 @@ export class MemberRouter extends AbstractRouter {
@Put('/response')
public addResponse(
@HeaderParam('authorization') token: string, //
@BodyParam('response') value: string, //
@BodyParam('response', { required: false }) value: string, //
): object {
if (!Array.isArray(value) && !['string', 'number'].includes(typeof value)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment