src/error-status.js   A
last analyzed

Complexity

Total Complexity 2
Complexity/F 1

Size

Lines of Code 26
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 13
mnd 0
bc 0
fnc 2
dl 0
loc 26
ccs 2
cts 2
cp 1
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0
1 2
const errorCodesStatus = [
2
    {
3
        type: TypeError,
4
        status: 422,
5
    },
6
    {
7
        type: RangeError,
8
        status: 404,
9
    },
10
    {
11
        type: Error,
12
        status: 500,
13
    },
14
];
15
16
/**
17
 * Get a http status when you send an error.
18
 * When it is a error, throw back the error.
19
 *
20
 * @param {Error} error
21
 *
22
 * @return {number}
23
 */
24
export default (error) =>
25 13
    errorCodesStatus.find((errorCode) => error instanceof errorCode.type)
26
        .status;
27