You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
handleError(error, "You are not allowed to access this resource.");
60
+
// If AxiosError and status === 403: 'You are not allowed to access this resource.'
61
+
// If AxiosError and status === 500: 'You are not allowed to access this resource.'
49
62
```
50
63
51
64
### Server Error Handling
52
65
53
66
If the error status doesn't match any of the provided codes and is related to a server error (status 500+), the handler will return a default server error message.
handleError(error, 403, "Email or password incorrect.");
72
-
// If AxiosError and status !== 403 | status > 500: "An unknown error occurred."
73
-
// If Error : error.message
85
+
// If AxiosError and status !== 403 | status > 500: 'An unknown error occurred.'
86
+
// If generic Error : error.message
74
87
// If unknown error : 'An unknown error occurred.'
75
88
```
76
89
77
90
### Options
78
91
79
-
#### `errorCodesToCheck` (required)
80
-
81
-
-**Type**: `number | number[]`
82
-
-**Description**: The status code(s) to check for in the Axios error response. You can pass a single status code or an array of status codes.
83
-
84
92
#### `errorMessages` (required)
85
93
86
94
-**Type**: `string | Record<number, string>`
87
-
-**Description**: The custom error message(s) for the specified status code(s). If you pass a single string, it will be used for all errors.
95
+
-**Description**: The custom error message(s) for the specified status code(s). If you pass a single string, it will be used for all errors. If passing a `Record<number, string>`, the object keys represent status codes, and values represent corresponding error messages.
96
+
97
+
If passing a `Record<number, string>`, must not fill `errorCodesToCheck`, the object keys represent status codes and values represent corresponding error messages.
98
+
99
+
#### `errorCodeToCheck` (optional)
100
+
101
+
-**Type**: `number`
102
+
-**Description**: The specific status code to check for in the Axios error response. Must be specified if `errorMessages` is a string.
103
+
104
+
#### `serverErrorMessage` (optional)
105
+
106
+
-**Type**: `string`
107
+
-**Description**: The message to show for server errors (status codes >= 500). Default is 'A server error occurred. Please try again later.'
108
+
109
+
#### `unknownErrorMessage` (optional)
88
110
89
-
If passing a `Record<number, string>`, the object keys represent status codes and values represent corresponding error messages.
111
+
-**Type**: `string`
112
+
-**Description**: The message to show when the error type is unknown. Default is 'An unknown error occurred.'
0 commit comments