1

I have a fetch function that takes a URL and gives out the response.

public getHTTPResponse(URL : string) {
    fetch(URL).then(function(response) {
        return response;
    })
}

I try to use the response in a IF-statement.

For example if the response is 200 it should be true. So far I have:

if (this.getHTTPResponse(item.ListUrl) === )

Where item.ListUrl is a link. I can't get my head around on what I should have on the right side of the operator to test if the response is 200 (or any other for that matter). Any help?

Michael
  • 3,093
  • 7
  • 39
  • 83
Arte
  • 397
  • 1
  • 4
  • 14
  • You can't do anything on the right hand side; getHTTPResponse doesn't currently return anything, and if it did comparing promise equality rarely makes sense. – jonrsharpe Nov 18 '18 at 09:26
  • Possible duplicate of [How to get data returned from fetch() promise?](https://stackoverflow.com/questions/47604040/how-to-get-data-returned-from-fetch-promise) – jonrsharpe Nov 18 '18 at 09:27
  • Can you post your success and failure response here so we can see what type of response it's returning – Prashant Pimpale Nov 18 '18 at 09:58

1 Answers1

4

The response object has a property status which value is an integer. Try like that:

  fetch(URL)
   .then(function(response) {
      if(response.status === 200) {
         // do something
       };
     })
Stundji
  • 855
  • 7
  • 17