Skip to content

Instantly share code, notes, and snippets.

@ethercrow
Created August 26, 2018 13:20
Show Gist options
  • Save ethercrow/526e83eda39e7ccd81e44bbcb6ff9e53 to your computer and use it in GitHub Desktop.
Save ethercrow/526e83eda39e7ccd81e44bbcb6ff9e53 to your computer and use it in GitHub Desktop.
Req config for flaky services (retry on everything >= 500)
-- Usage:
--
-- import Network.HTTP.Flaky
--
-- instance MonadHttp MyMonad where
-- handleHttpException = liftIO . throwIO
-- getHttpConfig = return flakyConfig
module Network.HTTP.Flaky
( flakyConfig
) where
import Debug.Trace
import Network.HTTP.Req
import Data.Default
import Network.HTTP.Client (responseStatus, Response)
import Network.HTTP.Types (statusCode)
flakyConfig :: HttpConfig
flakyConfig = def {httpConfigRetryJudge = judgeOfFlakiness}
judgeOfFlakiness :: _RetryStatus -> Response x -> Bool
judgeOfFlakiness _ _ | trace "judging" False = error "move along"
judgeOfFlakiness _ resp = statusCode (responseStatus resp) >= 500
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment