-
Notifications
You must be signed in to change notification settings - Fork 79
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 should communications errors be caught? #26
Comments
What you're seeing here is a little different from the usual usage of Aff/Affjax because you're in the Halogen If there is a response from the server then you will receive an Aff provides various other methods for error handling too though. For instance, you can catch errors by using |
Thanks. Using The challenge here is knowing when exceptions may be thrown, and hence calling |
I'd agree. I'd be open to a the idea of exposing connection errors in the type, rather than propagating them through Aff, although I think @garyb found that browsers don't really provide any data on the failure. |
Yeah, unfortunately there is no info about what went wrong when a request fails via I couldn't even find a good list of conditions in which it would fail this way - as far as I can tell it's whenever a response never comes back from the server, but there are myriad reasons why that might be. |
I was doing something quite similar with resEi <- liftAff $ try $ AJ.get AJ.string $ urlToString jsonUrl
-- ... snip ...
let res = join $ lmap AJ.XHRError resEi
in case res of
Left err -> errorBox $ EX.error $
"GET /api response failed to decode: " <> AJ.printError err
Right response -> pure $ Tuple doi (Just $ readRecordJSON response.body) |
A 404 won't raise this kind of error - it might be that the content returned with a 404 will not decode with the appropriate content type, and that is what is causing the error, but a 404 itself will just be treated like any other response. The error being talked about in this issue is when a request fails entirely - there's no response at all from the server. |
Ah, yes, the issue is that |
I'm trying out this library (and purescript) for the first time. The only example of which I am aware is this:
https://github.com/slamdata/purescript-halogen/blob/master/examples/ajax/src/Main.purs
Because the
AffJaxResponse
type has a field containing the http status code, I had assumed that errors would be reflected into this field. If I modify the example, I can see that it is set on success:If however, I force an error to occur (eg by making the URL invalid), then the code aborts rather than handles the error, as shown in the javascript console.
How should the example code be modified to capture errors such they the can can handled appropriately?
The text was updated successfully, but these errors were encountered: