parseResponseBody()function
parseResponseBody(response: Response, caller: AnyCaller = parseResponseBody): Promise<unknown>
| Param | Type | |
|---|---|---|
response | Response | The Response whose body to parse. required |
caller | AnyCaller | Identity of the calling function for error attribution. Defaults to parseResponseBody |
| Return | |
|---|---|
Promise<unknown> | unknown If content type is application/json and has valid JSON (including undefined if the content is empty). |
unknown | unknown If content type is multipart/form-data then convert it to a simple Data object. |
unknown | string If content type is text/plain or anything else (including "" empty string if it's empty). |
| Throws | |
|---|---|
ResponseError | If the content is not text/plain or application/json with valid JSON. |
Parse the body content of an HTTP Response based on its content type, or throw ResponseError if the content could not be parsed.
Examples
const body = await parseResponseBody(response);