fix tests, move most errors to shared code

This commit is contained in:
Matteo Pagliazzi
2016-03-03 19:16:03 +01:00
parent 80f791c86b
commit 96c582e062
7 changed files with 37 additions and 59 deletions

View File

@@ -1,7 +1,7 @@
// The error handler middleware that handles all errors
// and respond to the client
import logger from '../../libs/api-v3/logger';
import CustomError from '../../../../common/script/api-v3/customError';
import { CustomError } from '../../../../common/script/api-v3/errors';
import {
BadRequest,
InternalServerError,
@@ -24,12 +24,6 @@ export default function errorHandler (err, req, res, next) { // eslint-disable-l
// If we can't identify it, respond with a generic 500 error
let responseErr = err instanceof CustomError ? err : null;
// TODO don't return always 400 for errors in common code
// If CustomError but without httpCode then they come from shared code, treat as 400s
if (err instanceof CustomError && !err.httpCode) {
err.httpCode = 400;
}
// Handle errors created with 'http-errors' or similar that have a status/statusCode property
if (err.statusCode && typeof err.statusCode === 'number') {
responseErr = new CustomError();