@@ -8,39 +8,32 @@ import {
8
8
export const generateError = (
9
9
error : Error | AxiosError ,
10
10
intentMessage : string
11
- ) : ServerError => {
11
+ ) => {
12
12
if ( error instanceof AxiosError ) {
13
13
const message = error . response ?. data
14
14
? JSON . stringify ( error . response ?. data )
15
15
: error . message ;
16
16
const status = error . response ?. status || 500 ;
17
+ var errorType : IntegrationErrorType ;
17
18
switch ( status ) {
18
19
case 401 :
19
- return new ServerError (
20
- DELEGATE_TO_FRONTEND_CODE ,
21
- IntegrationErrorType . INTEGRATION_REFRESH_ERROR
22
- ) ;
20
+ errorType = IntegrationErrorType . INTEGRATION_REFRESH_ERROR ;
21
+ break ;
23
22
case 403 :
24
- return new ServerError (
25
- DELEGATE_TO_FRONTEND_CODE ,
26
- IntegrationErrorType . INTEGRATION_ERROR_FORBIDDEN
27
- ) ;
23
+ errorType = IntegrationErrorType . INTEGRATION_ERROR_FORBIDDEN ;
24
+ break ;
28
25
case 409 :
29
- return new ServerError (
30
- DELEGATE_TO_FRONTEND_CODE ,
31
- IntegrationErrorType . ENTITY_ERROR_CONFLICT
32
- ) ;
26
+ errorType = IntegrationErrorType . ENTITY_ERROR_CONFLICT ;
27
+ break ;
33
28
case 502 :
34
29
case 503 :
35
30
case 504 :
36
- return new ServerError (
37
- DELEGATE_TO_FRONTEND_CODE ,
38
- IntegrationErrorType . INTEGRATION_ERROR_UNAVAILABLE
39
- ) ;
40
-
31
+ errorType = IntegrationErrorType . INTEGRATION_ERROR_UNAVAILABLE ;
32
+ break ;
41
33
default :
42
- return new ServerError ( status , `${ intentMessage } (${ message } )` ) ;
34
+ throw new ServerError ( status , `${ intentMessage } (${ message } )` ) ;
43
35
}
36
+ throw new ServerError ( DELEGATE_TO_FRONTEND_CODE , errorType ) ;
44
37
}
45
- return new ServerError ( 500 , "An internal error occurred" ) ;
38
+ throw new ServerError ( 500 , "An internal error occurred" ) ;
46
39
} ;
0 commit comments