Passed
Push — main ( 74e679...90c63f )
by Julia
01:01 queued 20s
created

server/src/middleware/error-handler.js   A

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 28
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 11
mnd 1
bc 1
fnc 1
dl 0
loc 28
bpm 1
cpm 2
noi 1
c 0
b 0
f 0
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
A error-handler.js ➔ errorHandler 0 16 2
1
import express from "express";
2
3
/**
4
 *
5
 * @param {Error} err
6
 * @param {express.Request} req
7
 * @param {express.Response} res
8
 * @param {express.NextFunction} next
9
 */
10
// eslint-disable-next-line no-unused-vars
11
function errorHandler(err, req, res, next) {
12
    if (res.headersSent) {
13
        return next(err);
14
    }
15
16
    console.error(err.stack);
17
18
    const statusCode = res.statusCode || 500;
19
20
    res.status(statusCode).json({
21
        errors: {
22
            message: err.message,
23
            code: statusCode
24
        }
25
    });
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
26
}
27
28
export default errorHandler;
29