(error: unknown)
| 105 | }; |
| 106 | |
| 107 | export const getErrorDetail = (error: unknown): string | undefined => { |
| 108 | if (error instanceof DetailedError) { |
| 109 | return error.detail; |
| 110 | } |
| 111 | |
| 112 | // APIErrors that are empty still benefit from checking the developer |
| 113 | // console if no detail is provided. So only use the detail field if |
| 114 | // it is not empty. |
| 115 | if (isApiError(error) && error.response.data.detail) { |
| 116 | return error.response.data.detail; |
| 117 | } |
| 118 | |
| 119 | if (isApiErrorResponse(error) && error.detail) { |
| 120 | return error.detail; |
| 121 | } |
| 122 | |
| 123 | if ( |
| 124 | isApiValidationError(error) && |
| 125 | // Ensure that the validations array is not `[]` (empty array). |
| 126 | Array.isArray(error.response.data.validations) && |
| 127 | error.response.data.validations.length > 0 |
| 128 | ) { |
| 129 | return getValidationErrorMessage(error); |
| 130 | } |
| 131 | |
| 132 | if (error instanceof Error) { |
| 133 | return "Please check the developer console for more details."; |
| 134 | } |
| 135 | |
| 136 | return undefined; |
| 137 | }; |
| 138 | |
| 139 | export const getErrorStatus = (error: unknown): number | undefined => { |
| 140 | if (isApiError(error)) { |
no test coverage detected