(
request: HttpRequest<any>,
binContent: Uint8Array<ArrayBuffer>,
contentType: string,
status: number,
)
| 334 | } |
| 335 | |
| 336 | private parseBody( |
| 337 | request: HttpRequest<any>, |
| 338 | binContent: Uint8Array<ArrayBuffer>, |
| 339 | contentType: string, |
| 340 | status: number, |
| 341 | ): string | ArrayBuffer | Blob | object | null { |
| 342 | switch (request.responseType) { |
| 343 | case 'json': |
| 344 | // stripping the XSSI when present |
| 345 | const text = getTextDecoder(contentType).decode(binContent).replace(XSSI_PREFIX, ''); |
| 346 | if (text === '') { |
| 347 | return null; |
| 348 | } |
| 349 | try { |
| 350 | return JSON.parse(text) as object; |
| 351 | } catch (e: unknown) { |
| 352 | // Allow handling non-JSON errors (!) as plain text, same as the XHR |
| 353 | // backend. Without this special sauce, any non-JSON error would be |
| 354 | // completely inaccessible downstream as the `HttpErrorResponse.error` |
| 355 | // would be set to the `SyntaxError` from then failing `JSON.parse`. |
| 356 | if (status < 200 || status >= 300) { |
| 357 | return text; |
| 358 | } |
| 359 | throw e; |
| 360 | } |
| 361 | case 'text': |
| 362 | return getTextDecoder(contentType).decode(binContent); |
| 363 | case 'blob': |
| 364 | return new Blob([binContent], {type: contentType}); |
| 365 | case 'arraybuffer': |
| 366 | return binContent.buffer; |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | private createRequestInit(req: HttpRequest<any>): RequestInit { |
| 371 | if (req.reportUploadProgress) { |
no test coverage detected