Extracted routes from controllers, wrote readme's

This commit is contained in:
ireic
2020-01-11 00:39:06 +01:00
parent 5cc0d49964
commit fe4ef2f981
15 changed files with 224 additions and 185 deletions

View File

@@ -0,0 +1,21 @@
import { ErrorRequestHandler } from 'express';
import { pick } from 'lodash';
import { CustomError } from 'errors';
export const handleError: ErrorRequestHandler = (error, _req, res, _next) => {
console.error(error);
const isErrorSafeForClient = error instanceof CustomError;
const clientError = isErrorSafeForClient
? pick(error, ['message', 'code', 'status', 'data'])
: {
message: 'Something went wrong, please contact our support.',
code: 'INTERNAL_ERROR',
status: 500,
data: {},
};
res.status(clientError.status).send({ error: clientError });
};