Classes
Methods
(async, static) request(url, methodopt, bodyopt, optsopt) → {Promise.<module:request.ValidResponse>}
Make a request to a URL.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
url |
string |
the URL to send a request to. |
||
method |
String |
<optional> |
"GET" |
the HTTP method to use (GET, POST, PUT, DELETE) |
body |
Object | String |
<optional> |
the content of the body of the request. If it's an object, will automatically apply |
|
opts |
* |
<optional> |
{} |
|
- Source:
Throws:
-
-
If the response contains an HTTP Status Code in the error range (4xx or 5xx), then
request()will throw anHttpError. This can be useful to detect, for example, a401 Unauthorized, a404 Not Found, a500 Internal Server Error, or any other HTTP status code.This error type can be detected by checking if
error instanceof HttpError.
-
-
-
In the event of a network error, a
NetworkErrorwill throw. This can happen if:- the user disconnects from their WiFi network
- the servers are down
- the request times out
In the real world, this can happen if a user travels through a tunnel, disconnecting them from their mobile network. It's an important edge case to account for.
This error type can be detected by checking if
error instanceof NetworkError.
-