mirror of
https://github.com/bpatrik/pigallery2.git
synced 2024-12-02 09:12:07 +02:00
Improving error logging for handled server side errors.
Looking for: "ForbiddenError: invalid csrf token"
This commit is contained in:
parent
ee355dd012
commit
9df2b8fbaa
@ -30,7 +30,7 @@ export const winstonSettings = {
|
||||
exitOnError: false
|
||||
};
|
||||
|
||||
type logFN = (...args: (string | number)[]) => {};
|
||||
export type logFN = (...args: (string | number)[]) => {};
|
||||
|
||||
export const Logger: {
|
||||
error: logFN,
|
||||
|
@ -7,6 +7,7 @@ import {NotificationManager} from '../model/NotifocationManager';
|
||||
import {Logger} from '../Logger';
|
||||
import {SharingDTO} from '../../common/entities/SharingDTO';
|
||||
import {Utils} from '../../common/Utils';
|
||||
import {LoggerRouter} from '../routes/LoggerRouter';
|
||||
|
||||
export class RenderingMWs {
|
||||
|
||||
@ -92,6 +93,7 @@ export class RenderingMWs {
|
||||
if (err instanceof ErrorDTO) {
|
||||
if (err.details) {
|
||||
Logger.warn('Handled error:');
|
||||
LoggerRouter.log(Logger.warn, req, res);
|
||||
console.log(err);
|
||||
delete (err.details); // do not send back error object to the client side
|
||||
|
||||
@ -103,7 +105,7 @@ export class RenderingMWs {
|
||||
const message = new Message<any>(err, null);
|
||||
return res.json(message);
|
||||
}
|
||||
NotificationManager.error('unknown server error', err);
|
||||
NotificationManager.error('Unknown server error', err);
|
||||
return next(err);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import {Express, NextFunction, Request, Response} from 'express';
|
||||
import {Logger} from '../Logger';
|
||||
import {logFN, Logger} from '../Logger';
|
||||
|
||||
declare global {
|
||||
namespace Express {
|
||||
@ -14,43 +14,34 @@ declare global {
|
||||
* Adds logging to express
|
||||
*/
|
||||
export class LoggerRouter {
|
||||
public static log(loggerFn: logFN, req: Request, res: Response) {
|
||||
if (req.logged === true) {
|
||||
return;
|
||||
}
|
||||
req.logged = true;
|
||||
req._startTime = Date.now();
|
||||
const end = res.end;
|
||||
res.end = (a?: any, b?: any, c?: any) => {
|
||||
res.end = end;
|
||||
res.end(a, b, c);
|
||||
loggerFn(req.method, req.url, res.statusCode, (Date.now() - req._startTime) + 'ms');
|
||||
};
|
||||
}
|
||||
|
||||
public static route(app: Express) {
|
||||
|
||||
app.get('/api*', (req: Request, res: Response, next: NextFunction) => {
|
||||
req._startTime = Date.now();
|
||||
req.logged = true;
|
||||
const end = res.end;
|
||||
res.end = (a?: any, b?: any, c?: any) => {
|
||||
res.end = end;
|
||||
res.end(a, b, c);
|
||||
Logger.verbose(req.method, req.url, res.statusCode, (Date.now() - req._startTime) + 'ms');
|
||||
};
|
||||
LoggerRouter.log(Logger.verbose, req, res);
|
||||
return next();
|
||||
});
|
||||
|
||||
app.get('/node_modules*', (req: Request, res: Response, next: NextFunction) => {
|
||||
req._startTime = Date.now();
|
||||
req.logged = true;
|
||||
const end = res.end;
|
||||
res.end = (a?: any, b?: any, c?: any) => {
|
||||
res.end = end;
|
||||
res.end(a, b, c);
|
||||
Logger.silly(req.method, req.url, res.statusCode, (Date.now() - req._startTime) + 'ms');
|
||||
};
|
||||
LoggerRouter.log(Logger.silly, req, res);
|
||||
return next();
|
||||
});
|
||||
|
||||
app.use((req: Request, res: Response, next: NextFunction) => {
|
||||
if (req.logged === true) {
|
||||
return next();
|
||||
}
|
||||
req._startTime = Date.now();
|
||||
const end = res.end;
|
||||
res.end = (a?: any, b?: any, c?: any) => {
|
||||
res.end = end;
|
||||
res.end(a, b, c);
|
||||
Logger.debug(req.method, req.url, res.statusCode, (Date.now() - req._startTime) + 'ms');
|
||||
};
|
||||
LoggerRouter.log(Logger.debug, req, res);
|
||||
return next();
|
||||
});
|
||||
|
||||
|
@ -26,6 +26,9 @@ export class ShareSettingsService extends AbstractSettingsService<ClientConfig.S
|
||||
|
||||
|
||||
public getSharingList(): Promise<SharingDTO[]> {
|
||||
if (!this._settingsService.settings.value.Client.Sharing.enabled) {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
return this._networkService.getJson('/share/list');
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user