FetchResponse
The response for a FetchRequest.
Implements
Iterable
<[string
,string
]>
Accessors
body
The response body, or null
if there was no body.
Returns
null
| Readonly
<Uint8Array
>
Source
bodyJson
The response body, decoded as JSON.
An error is thrown if the body is invalid JSON-encoded data or if there was no body.
Returns
any
Source
bodyText
The response body as a UTF-8 encoded string, or the empty string (i.e. ""
) if there was no body.
An error is thrown if the body is invalid UTF-8 data.
Returns
string
Source
headers
The response headers. All keys are lower-case.
Returns
Record
<string
, string
>
Source
request
The request made for this response.
Returns
null
| FetchRequest
Source
statusCode
The response status code.
Returns
number
Source
statusMessage
The response status message.
Returns
string
Source
Methods
assertOk()
Throws a SERVER_ERROR
if this response is not ok.
Returns
void
Throws
If the response is not ok.
Source
getHeader()
Get the header value for key
, ignoring case.
Parameters
Parameter | Type | Description |
---|---|---|
key | string | The header key to retrieve. |
Returns
string
The header value.
Source
hasBody()
Returns true if the response has a body.
Returns
this is FetchResponse & Object
True if the response has a body.
Throws
If the body is invalid UTF-8 data.
Source
makeServerError()
Return a Response with matching headers and body, but with an error status code (i.e. 599) and message
with an
optional error
.
Parameters
Parameter | Type | Description |
---|---|---|
message ? | string | The error message to use. |
error ? | Error | The error to use. |
Returns
The error response.
Source
ok()
Returns true if this response was a success statusCode.
Returns
boolean
Source
throwThrottleError()
If called within a request.processFunc call, causes the request to retry as if
throttled for stall
milliseconds.
Parameters
Parameter | Type | Description |
---|---|---|
message ? | string | The error message to use. |
stall ? | number | The number of milliseconds to stall before retrying. |
Returns
never
Throws
If stall
is not a non-negative integer.
Source
Was this page helpful?