(
request: HttpRequest<any>,
binContent: Uint8Array<ArrayBuffer>,
contentType: string,
status: number,
)
| 370 | } |
| 371 | |
| 372 | private parseBody( |
| 373 | request: HttpRequest<any>, |
| 374 | binContent: Uint8Array<ArrayBuffer>, |
| 375 | contentType: string, |
| 376 | status: number, |
| 377 | ): string | ArrayBuffer | Blob | object | null { |
| 378 | switch (request.responseType) { |
| 379 | case 'json': |
| 380 | // stripping the XSSI when present |
| 381 | const text = new TextDecoder().decode(binContent).replace(XSSI_PREFIX, ''); |
| 382 | if (text === '') { |
| 383 | return null; |
| 384 | } |
| 385 | try { |
| 386 | return JSON.parse(text) as object; |
| 387 | } catch (e: unknown) { |
| 388 | // Allow handling non-JSON errors (!) as plain text, same as the XHR |
| 389 | // backend. Without this special sauce, any non-JSON error would be |
| 390 | // completely inaccessible downstream as the `HttpErrorResponse.error` |
| 391 | // would be set to the `SyntaxError` from then failing `JSON.parse`. |
| 392 | if (status < 200 || status >= 300) { |
| 393 | return text; |
| 394 | } |
| 395 | throw e; |
| 396 | } |
| 397 | case 'text': |
| 398 | return getTextDecoder(contentType).decode(binContent); |
| 399 | case 'blob': |
| 400 | return new Blob([binContent], {type: contentType}); |
| 401 | case 'arraybuffer': |
| 402 | return binContent.buffer; |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | private createRequestInit(req: HttpRequest<any>): RequestInit { |
| 407 | if (req.reportUploadProgress) { |
no test coverage detected