Search.../

ok

Indicates if the request was successful, meaning its status is in the range 2xx.

Type:

booleanRead Only

Was this helpful?

Get whether a response is ok.

Copy Code
1let isOk = httpResponse.ok; // true
Get a resource and the response information

Copy Code
1import {fetch} from 'wix-fetch';
2
3// ...
4
5fetch("https://someapi.com/api/someendpoint", {"method": "get"})
6 .then( (httpResponse) => {
7 let url = httpResponse.url;
8 let statusCode = httpResponse.status;
9 let statusText = httpResponse.statusText;
10 let headers = httpResponse.headers;
11 let bodyUsed = httpResponse.bodyUsed;
12 if (httpResponse.ok) {
13 return httpResponse.json();
14 }
15 else {
16 return Promise.reject("Fetch did not succeed");
17 }
18 } )
19 .then( (json) => {
20 console.log(json.someKey);
21 } )
22 .catch( (err) => {
23 console.log(err);
24 } );