-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientError.js
More file actions
47 lines (35 loc) · 1.46 KB
/
ClientError.js
File metadata and controls
47 lines (35 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const MESSAGE_GENERIC_ERROR = "Problemas con la aplicación. Contactese con el administrador"
const MESSAGE_NETWORK_ERROR = "Problemas con el servidor. Contactese con el administrador.";
const MESSAGE_VALIDATION = "Problemas de validación. Revise los datos ingresados";
const MESSAGE_FORBIDEN = "No Autorizado"
const MESSAGE_UNAUTHENTICATED = "Requiere login"
class ClientError extends Error {
constructor(error) {
super(error.message);
this.name = "ClientError";
this.inputErrors = {}
this.showMessage = ""
if (error.networkError) {
this.showMessage = MESSAGE_NETWORK_ERROR
} else if (error.graphQLErrors && error.graphQLErrors.length > 0) {
this.processFrapjQLErrors(error.graphQLErrors)
} else {
this.showMessage = MESSAGE_GENERIC_ERROR
}
}
processFrapjQLErrors(graphQLErrors) {
graphQLErrors.forEach(gqlError => {
if (gqlError.extensions.code == "BAD_USER_INPUT") {
this.showMessage = MESSAGE_VALIDATION
this.inputErrors = {...this.inputErrors, ...gqlError.extensions.exception.inputErrors}
}
if (gqlError.extensions.code == "FORBIDDEN") {
this.showMessage = MESSAGE_FORBIDEN
}
if (gqlError.extensions.code == "UNAUTHENTICATED") {
this.showMessage = MESSAGE_UNAUTHENTICATED
}
})
}
}
module.exports = ClientError;