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

Complexity

Total Complexity 3
Complexity/F 3

Size

Lines of Code 30
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 12
mnd 2
bc 2
fnc 1
dl 0
loc 30
ccs 6
cts 6
cp 1
bpm 2
cpm 3
noi 0
c 0
b 0
f 0
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
A error-handler.js ➔ errorHandler 0 18 3
1
// eslint-disable-next-line no-unused-vars
2
import express from "express";
3
4
/**
5
 *
6
 * @param {Error} err
7
 * @param {express.Request} req
8
 * @param {express.Response} res
9
 * @param {express.NextFunction} next
10
 */
11
// eslint-disable-next-line no-unused-vars
12
function errorHandler(err, req, res, next) {
13 50
    if (res.headersSent) {
14 1
        return next(err);
15
    }
16
17 49
    if (process.env.NODE_ENV !== 'test') {
18 1
        console.error(err.stack);
19
    }
20
21 49
    const statusCode = 500;
22
23 49
    return res.status(statusCode).json({
24
        errors: {
25
            message: err.message,
26
            code: statusCode
27
        }
28
    });
29
}
30
31
export default errorHandler;
32