calions-app/jsonapi-http-retry/2.0.0

Renamed to FabienHenon/jsonapi-http-retry. It is published under that name, and new versions come out there.

Versions published as calions-app/jsonapi-http-retry still install under that name. 2 versions of 2 come from the new location (see their notes).

Rerouted (renamed, verified). The GitHub user or repository was renamed. The tag is still there, at the new name. The Lamdera package server serves a copy recovered from https://github.com/FabienHenon/jsonapi-http-retry.

What we checked: The repo moved to github.com/FabienHenon/jsonapi-http-retry. Rebuilt with git archive from commit e6c3bc1260f8 of https://github.com/FabienHenon/jsonapi-http-retry (zip prefix calions-app-jsonapi-http-retry-e6c3bc1/, America/Los_Angeles times): the zip is byte-identical to the one package.elm-lang.org recorded, SHA-1 13e53041cbea94520506e88de268624f601601f1.

The Lamdera compiler uses this copy and prints a one-line notice saying so. elm itself fails to download this version.

Details · package.elm-lang.org's zip: https://github.com/calions-app/jsonapi-http-retry/zipball/2.0.0/

Http.CmdRetry

Tries to perform a Task and retry it upon failure, allowing you to execute other Cmds between each failure.

The following example executes a request with a retry policy when the request fails and executes a port before each new retry:

type Msg
    = OnRetry (Http.CmdRetry.RetryContext Msg Entity)
    | OnEntityRetrieved (RemoteData.RemoteData Http.Error.RequestError Entity)


type alias Model =
    { entity : RemoteData.RemoteData Http.Error.RequestError Entity }


init : ( Model, Cmd Msg )
init =
    ( { entity = RemoteData.Loading }
    , getEntity
        |> Http.CmdRetry.with
            [ Http.Retry.maxDuration 7000
            , Http.Retry.exponentialBackoff { interval = 500, maxInterval = 3000 }
            ]
            [ Http.Retry.onUnauthenticatedStatus ]
            OnRetry
    )


update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
    case msg of
        OnRetry retryContext ->
            ( model
            , Http.CmdRetry.newAttempt
                executePort
                OnEntityRetrieved
                retryContext
            )


        OnEntityRetrieved entity ->
            ( { model | entity = entity }, Cmd.none )


getEntity : Task Never (RemoteData.RemoteData Http.Error.RequestError Entity)
getEntity =
    Request.request
        { url = "<http://endpoint">
        , headers = []
        , body = Json.Encode.object []
        , documentDecoder = JsonApi.Decode.resources "resource-type" entityDecoder
        }

Retry

List (Policy RequestError)
-> List FailureCondition
-> (RetryContext msg data -> msg)
-> Task Never (RemoteData RequestError data)
-> Cmd msg

Tries to execute the given task. You will receive a message with the retry context. From there you will call newAttempt which will handle your request retry, allowing you to execute a Cmd before the next retry.

originalTask
    |> Http.CmdRetry.with
        [ Http.Retry.maxDuration 7000
        , Http.Retry.exponentialBackoff { interval = 500, maxInterval = 3000 }
        ]
        [ Http.Retry.onUnauthenticatedStatus ]
        OnRetry
(RequestError -> Cmd msg)
-> (RemoteData RequestError data -> msg)
-> RetryContext msg data
-> Cmd msg

Attempt a new retry from your update function with the RetryContext you received. The first parameter allows you to execute a Cmd just before the next retry. The second parameter is the message you want to send when the request finally succeeded or failed (after all configured retries)

update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
    case msg of
        OnRetry retryContext ->
            ( model
            , Http.CmdRetry.newAttempt
                (\lastError ->
                    doSomethingWithLastError lastError
                )
                OnRequestDone
                retryContext
            )

Types

type RetryContext msg data

Type used by the module to keep the context of the retry process. You will never handle it directly

msg is your Msg type and data is the data you you to receive from your request.