API integration handle 410 request with JSON body

Hi, I try to integrate a IAM API, we use browser login flow type, the IAM server return a Flow id to get information required to build the login form. Decoding the Ok response is perfectly fine, but if a delay occurs between the flow id request and the call the next API, the flow can be gone, so the API response if a 410, but with a JSON body containing useful information to handle user redirect…

The problem, my Msg LoginFlow (Result Http.Error LoginFlow) receive a NetworkError when handling the 410 request and my decoder are not used and the response body unavailable.

How to solve my current situation ? Thanks a lots for your help.

Use expectStringResponse. This way, you will be able to extract data from the body of the response in case of 410.

Fast response, thanks a lots, I will explore I will try to understand the expectJson and implement my own based on your suggestion.

Sorry, but I have more question

expectJson : (Result Http.Error a -> msg) -> Decode.Decoder a -> Expect msg
expectJson toMsg decoder =
    Http.expectStringResponse toMsg <|
        \response ->
            case response of
                BadUrl_ url ->
                    Err (BadUrl url)

                Timeout_ ->
                    Err Timeout

                NetworkError_ ->
                    Err NetworkError

                BadStatus_ metadata body ->
                    Err (BadStatus metadata.statusCode)

                GoodStatus_ metadata body ->
                    case Decode.decodeString decoder body of
                        Ok value ->
                            Ok value

                        Err err ->
                            Err (BadBody (Decode.errorToString err))

A 410 trigger the `NetworkError_` branch of my case and did not pass by a branch where I can access to status code or the body message ... maybe I'm not experienced enough to see where I can found a solution.

I’m stupid it’s not an Eml problem, but a CORS issue … so Elm is right, can not parse the body of the request … stupid me, back to my server configuration

Please don’t insult elm programmers. :wink:

CORS is a frequent problem.


This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.