Closed lukashambsch closed 6 years ago
@meafmira Any ideas on how to do something like this? Or, is there a way I can at least access the status code of a 401 response? That way I would be able to handle the redirection there.
@lukashambsch I think you should use something like this:
external promiseErrorToJsObj : Js.Promise.error => Js.t('a) = "%identity";
Js.Promise.(
Instance.get(inst, "/")
|> then_(resp => resolve(Belt.Result.Ok(resp)))
|> catch(error => {
let error = error |> promiseErrorToJsObj;
Js.log(error##response##status);
resolve(Belt.Result.Error(error));
})
);
We need to use external
conversion function because of special behaviour of standard Js.Promise
module that returns Js.Promise.error
type.
I think we should add something error handler for this library. I'll do this soon. Thank you for this issue
I'll also add this example to readme file
@lukashambsch added readme here https://github.com/meafmira/bs-axios#error-handling
@meafmira Thanks! I really appreciate the response and love the library!
Is there a way to intercept 401 responses like with axios?
Here's an example: https://gist.github.com/yajra/5f5551649b20c8f668aec48549ef5c1f