module Ecluse.Core.Fault (
TransportFault (..),
transportFault,
TransportCause (..),
renderTransportCause,
transportRetryable,
RetryAfter (..),
boundedDetail,
) where
import Data.Text qualified as T
data TransportFault = TransportFault
{ TransportFault -> TransportCause
tfCause :: TransportCause
, TransportFault -> Text
tfDetail :: Text
}
deriving stock (TransportFault -> TransportFault -> Bool
(TransportFault -> TransportFault -> Bool)
-> (TransportFault -> TransportFault -> Bool) -> Eq TransportFault
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TransportFault -> TransportFault -> Bool
== :: TransportFault -> TransportFault -> Bool
$c/= :: TransportFault -> TransportFault -> Bool
/= :: TransportFault -> TransportFault -> Bool
Eq, Int -> TransportFault -> ShowS
[TransportFault] -> ShowS
TransportFault -> String
(Int -> TransportFault -> ShowS)
-> (TransportFault -> String)
-> ([TransportFault] -> ShowS)
-> Show TransportFault
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TransportFault -> ShowS
showsPrec :: Int -> TransportFault -> ShowS
$cshow :: TransportFault -> String
show :: TransportFault -> String
$cshowList :: [TransportFault] -> ShowS
showList :: [TransportFault] -> ShowS
Show)
transportFault :: TransportCause -> Text -> TransportFault
transportFault :: TransportCause -> Text -> TransportFault
transportFault TransportCause
cause Text
detail = TransportCause -> Text -> TransportFault
TransportFault TransportCause
cause (Text -> Text
boundedDetail Text
detail)
data TransportCause
=
TransportTimeout
|
TransportUnreachable
|
TransportTls
|
TransportProtocol
deriving stock (TransportCause -> TransportCause -> Bool
(TransportCause -> TransportCause -> Bool)
-> (TransportCause -> TransportCause -> Bool) -> Eq TransportCause
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: TransportCause -> TransportCause -> Bool
== :: TransportCause -> TransportCause -> Bool
$c/= :: TransportCause -> TransportCause -> Bool
/= :: TransportCause -> TransportCause -> Bool
Eq, Int -> TransportCause -> ShowS
[TransportCause] -> ShowS
TransportCause -> String
(Int -> TransportCause -> ShowS)
-> (TransportCause -> String)
-> ([TransportCause] -> ShowS)
-> Show TransportCause
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> TransportCause -> ShowS
showsPrec :: Int -> TransportCause -> ShowS
$cshow :: TransportCause -> String
show :: TransportCause -> String
$cshowList :: [TransportCause] -> ShowS
showList :: [TransportCause] -> ShowS
Show)
renderTransportCause :: TransportCause -> Text
renderTransportCause :: TransportCause -> Text
renderTransportCause = \case
TransportCause
TransportTimeout -> Text
"the peer did not answer in time"
TransportCause
TransportUnreachable -> Text
"the peer could not be reached"
TransportCause
TransportTls -> Text
"the TLS layer refused the peer"
TransportCause
TransportProtocol -> Text
"the peer's answer could not be used"
transportRetryable :: TransportCause -> Bool
transportRetryable :: TransportCause -> Bool
transportRetryable = \case
TransportCause
TransportTimeout -> Bool
True
TransportCause
TransportUnreachable -> Bool
True
TransportCause
TransportTls -> Bool
False
TransportCause
TransportProtocol -> Bool
False
newtype RetryAfter = RetryAfter Int
deriving stock (RetryAfter -> RetryAfter -> Bool
(RetryAfter -> RetryAfter -> Bool)
-> (RetryAfter -> RetryAfter -> Bool) -> Eq RetryAfter
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: RetryAfter -> RetryAfter -> Bool
== :: RetryAfter -> RetryAfter -> Bool
$c/= :: RetryAfter -> RetryAfter -> Bool
/= :: RetryAfter -> RetryAfter -> Bool
Eq, Eq RetryAfter
Eq RetryAfter =>
(RetryAfter -> RetryAfter -> Ordering)
-> (RetryAfter -> RetryAfter -> Bool)
-> (RetryAfter -> RetryAfter -> Bool)
-> (RetryAfter -> RetryAfter -> Bool)
-> (RetryAfter -> RetryAfter -> Bool)
-> (RetryAfter -> RetryAfter -> RetryAfter)
-> (RetryAfter -> RetryAfter -> RetryAfter)
-> Ord RetryAfter
RetryAfter -> RetryAfter -> Bool
RetryAfter -> RetryAfter -> Ordering
RetryAfter -> RetryAfter -> RetryAfter
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: RetryAfter -> RetryAfter -> Ordering
compare :: RetryAfter -> RetryAfter -> Ordering
$c< :: RetryAfter -> RetryAfter -> Bool
< :: RetryAfter -> RetryAfter -> Bool
$c<= :: RetryAfter -> RetryAfter -> Bool
<= :: RetryAfter -> RetryAfter -> Bool
$c> :: RetryAfter -> RetryAfter -> Bool
> :: RetryAfter -> RetryAfter -> Bool
$c>= :: RetryAfter -> RetryAfter -> Bool
>= :: RetryAfter -> RetryAfter -> Bool
$cmax :: RetryAfter -> RetryAfter -> RetryAfter
max :: RetryAfter -> RetryAfter -> RetryAfter
$cmin :: RetryAfter -> RetryAfter -> RetryAfter
min :: RetryAfter -> RetryAfter -> RetryAfter
Ord, Int -> RetryAfter -> ShowS
[RetryAfter] -> ShowS
RetryAfter -> String
(Int -> RetryAfter -> ShowS)
-> (RetryAfter -> String)
-> ([RetryAfter] -> ShowS)
-> Show RetryAfter
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> RetryAfter -> ShowS
showsPrec :: Int -> RetryAfter -> ShowS
$cshow :: RetryAfter -> String
show :: RetryAfter -> String
$cshowList :: [RetryAfter] -> ShowS
showList :: [RetryAfter] -> ShowS
Show)
boundedDetail :: Text -> Text
boundedDetail :: Text -> Text
boundedDetail = Text -> Text
T.copy (Text -> Text) -> (Text -> Text) -> Text -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Text -> Text
T.take Int
maxDetailChars
maxDetailChars :: Int
maxDetailChars :: Int
maxDetailChars = Int
512