| 74 | * @param response - original error |
| 75 | */ |
| 76 | export function httpErrorFromResponse(response: AxiosResponse): WebAPIHTTPError { |
| 77 | const error = errorWithCode( |
| 78 | new Error(`An HTTP protocol error occurred: statusCode = ${response.status}`), |
| 79 | ErrorCode.HTTPError, |
| 80 | ) as Partial<WebAPIHTTPError>; |
| 81 | error.statusCode = response.status; |
| 82 | error.statusMessage = response.statusText; |
| 83 | error.headers = response.headers; |
| 84 | error.body = response.data; |
| 85 | return (error as WebAPIHTTPError); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * A factory to create WebAPIPlatformError objects |