-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do I get the HTTP status code in the error case? #10
Comments
Hello with the current implementation you can't access it, it needs to be rewritten. For example, in Thoth.Fetch we use a custom implementation to preserve the error information. Right now, I guess there is 3 possibility:
|
I started using SimpleHttp, but only because that's the one I stumbled upon first. I will leave this open since having the error code seems like an important addition to |
@MangelMaxime we should provide a method that just runs https://github.com/fable-compiler/fable-fetch/blob/master/src/Fetch.fs#L375 without throwing if result is not ok |
@forki Indeed, it should be enough I think for I guess for let tryFetch (url: string) (init: RequestProperties list) : JS.Promise<Result<Response, Response>> =
GlobalFetch.fetch(RequestInfo.Url url, requestProps init)
|> Promise.map (fun response ->
if response.Ok
then Ok response
else Error response) I didn't test the code so it is possible that it doesn't compile. |
It looks like the response gets turned into a string for all response codes other than
2xx
:fable-fetch/src/Fetch.fs
Line 379 in b79a153
However, I need to handle HTTP codes differently in my app.
How can I get the HTTP code for error cases (e.g.
401
)?The text was updated successfully, but these errors were encountered: