mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
fix tests, move most errors to shared code
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user