Passed
Push — master ( 085900...85d83b )
by Mathieu
227:05 queued 225:41
created

client/src/normalizer/errors.js   A

Complexity

Total Complexity 6
Complexity/F 6

Size

Lines of Code 23
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 13
mnd 5
bc 5
fnc 1
dl 0
loc 23
rs 10
bpm 5
cpm 6
noi 0
c 0
b 0
f 0
1
export const errorNormalizer = e => {
2
  let message = e.message;
3
4
  if (e.response) {
5
    message = e.response.data.message
6
      ? e.response.data.message
7
      : e.response.data.error;
8
  }
9
10
  if (Array.isArray(message)) {
11
    const errors = [];
12
13
    for (const msg of message) {
14
      for (const constraint of Object.values(msg.constraints)) {
15
        errors.push(constraint);
16
      }
17
    }
18
19
    return errors;
20
  }
21
22
  return [message];
23
};
24