项目作者: FabienHenon

项目描述 :
Retry failed jsonapi requests with retry policies
高级语言: Elm
项目地址: git://github.com/FabienHenon/jsonapi-http-retry.git
创建时间: 2020-04-15T10:39:37Z
项目社区:https://github.com/FabienHenon/jsonapi-http-retry

开源协议:MIT License

下载


jsonapi-http-retry

Retry failed jsonapi requests with retry policies.

It is greatly inspired by the Retry package but aims to handle http requests from the jsonapi-http package.

With this package you can add retry policies to jsonapi-http requests errors.
You can choose specific errors that will trigger a retry: unauthenticated error, network error, etc…

You can also send Cmds between 2 failures with the Http.CmdRetry module.

Getting Started

Here is an example retrying requests 5 times maximum with a constant interval between retries, only for unauthenticated and unauthorized errors:

  1. import Http.Request
  2. import Http.Retry
  3. import Json.Encode
  4. import JsonApi.Decode
  5. request : Cmd Msg
  6. request =
  7. Request.request
  8. { url = "http://endpoint"
  9. , headers = []
  10. , body = Json.Encode.object []
  11. , documentDecoder = JsonApi.Decode.resources "resource-type" entityDecoder
  12. }
  13. |> Http.Retry.with
  14. [ Http.Retry.maxRetries 5
  15. , Http.Retry.exponentialBackoff { interval = 500, maxInterval = 3000 }
  16. ]
  17. [ Http.Retry.onUnauthenticatedStatus
  18. , Http.Retry.onUnauthorizedStatus
  19. ]
  20. |> Task.perform OnTaskCompleted