How to handle different response statuses of bs-fetch

So I have the following function

    let searchBike = (serialNumber: string) =>
      Fetch.fetchWithInit(
        `http://localhost:8000/bikes/search?serialNumber=${serialNumber}`,
        Fetch.RequestInit.make(~method_=Get, ()),
      )
      ->Js.Promise.then_(Fetch.Response.json, _)
      ->Js.Promise.then_(obj => {
        obj->Decode.bikeData->Js.Promise.resolve
      }, _)

Ho do I act if response is not 200?
Whenever I try to check the code, compiler says that there is no status field in the response.

Ok, I’ve figured out that to get stuff from response I need to call let status = Fetch.Response.status(response)

2 Likes

Can you please explain the functionality of this code?

It makes a request
Decodes the data as json
Decodes the json to bidedata type
And resolves the promise