Michal Blazejczyk
2017-12-03 03:36:28 UTC
Hi all,
I'm just beginning to get into Elm, and I encountered an issue. My Elm app
is making a POST request (Http.post) and when the server returns 400 or
401, I get NetworkError instead of BadStatus which means that I cannot
distinguish between error codes.
Looking at Javascript generated by the Elm compiler, I see:
function toTask(request, maybeProgress)
{
// ...
xhr.addEventListener('error', function() {
callback(_elm_lang$core$Native_Scheduler.fail({ ctor: 'NetworkError'
}));
});
xhr.addEventListener('timeout', function() {
callback(_elm_lang$core$Native_Scheduler.fail({ ctor: 'Timeout' }));
});
xhr.addEventListener('load', function() {
callback(handleResponse(xhr, request.expect.responseToResult));
});
// ...
}
For 400 and 401 responses, the browser triggers the listener for 'error'.
Is there a way to have Elm generate a BadStatus in this case?
Best,
Michal
I'm just beginning to get into Elm, and I encountered an issue. My Elm app
is making a POST request (Http.post) and when the server returns 400 or
401, I get NetworkError instead of BadStatus which means that I cannot
distinguish between error codes.
Looking at Javascript generated by the Elm compiler, I see:
function toTask(request, maybeProgress)
{
// ...
xhr.addEventListener('error', function() {
callback(_elm_lang$core$Native_Scheduler.fail({ ctor: 'NetworkError'
}));
});
xhr.addEventListener('timeout', function() {
callback(_elm_lang$core$Native_Scheduler.fail({ ctor: 'Timeout' }));
});
xhr.addEventListener('load', function() {
callback(handleResponse(xhr, request.expect.responseToResult));
});
// ...
}
For 400 and 401 responses, the browser triggers the listener for 'error'.
Is there a way to have Elm generate a BadStatus in this case?
Best,
Michal
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.