module Ecluse.Core.Fault.Http (
classifyTransport,
) where
import Network.HTTP.Client (
HttpException (HttpExceptionRequest, InvalidUrlException),
HttpExceptionContent (
ConnectionClosed,
ConnectionFailure,
ConnectionTimeout,
InternalException,
ResponseTimeout
),
)
import Network.TLS qualified as TLS
import Ecluse.Core.Fault (
TransportCause (TransportProtocol, TransportTimeout, TransportTls, TransportUnreachable),
TransportFault,
transportFault,
)
import Ecluse.Core.Text (displayExceptionT)
classifyTransport :: HttpException -> TransportFault
classifyTransport :: HttpException -> TransportFault
classifyTransport HttpException
err = TransportCause -> Text -> TransportFault
transportFault (HttpException -> TransportCause
causeOf HttpException
err) (HttpException -> Text
forall e. Exception e => e -> Text
displayExceptionT HttpException
err)
where
causeOf :: HttpException -> TransportCause
causeOf = \case
HttpExceptionRequest Request
_ HttpExceptionContent
content -> case HttpExceptionContent
content of
HttpExceptionContent
ConnectionTimeout -> TransportCause
TransportTimeout
HttpExceptionContent
ResponseTimeout -> TransportCause
TransportTimeout
ConnectionFailure SomeException
_ -> TransportCause
TransportUnreachable
HttpExceptionContent
ConnectionClosed -> TransportCause
TransportUnreachable
InternalException SomeException
inner
| Just (TLSException
_ :: TLS.TLSException) <- SomeException -> Maybe TLSException
forall e. Exception e => SomeException -> Maybe e
fromException SomeException
inner -> TransportCause
TransportTls
| Bool
otherwise -> TransportCause
TransportProtocol
HttpExceptionContent
_ -> TransportCause
TransportProtocol
InvalidUrlException String
_ String
_ -> TransportCause
TransportProtocol