You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This will make a `GET` request adding an `Authorization` header with the value `Bearer mytoken`. `bearerToken` can also be a `Promise`, a `function`, or a `function` that returns a `Promise` (an `async function`) and the hook will wait for the `bearerToken` to resolve before making the request.
236
236
237
-
## Utility Functions
238
-
239
-
The package includes some other utility functions that can be used outside the context of a hook.
240
-
241
-
### `checkStatus(response)`
242
-
243
-
[Read here](https://github.com/github/fetch#handling-http-error-statuses) for the inspiration for this function. It will reject fetch requests on any non-2xx response. It differs from the example in that it will try to parse a JSON body from the non-200 response and will set any `message` field (if it exists) from the JSON body as the error message. The fetch hooks use this internally.
244
-
245
-
```js
246
-
import { checkStatus } from"react-fetch-hooks";
247
-
248
-
//given a 400 Bad Request response with a JSON body of:
It will try to look for a `message` field first, and then an `exceptionMessage` falling back to the `statusText` if neither one exist or if the response body is not JSON.
0 commit comments