formatError :: Error -> String
formatError err =
    case err of
        ParseUrlError ->
            "Invalid docker-run url"

        HttpException exception ->
            case exception of
                Req.JsonHttpException reason ->
                    "Failed to decode json response from docker-run: " <> reason

                Req.VanillaHttpException httpException ->
                    case httpException of
                        InvalidUrlException url reason ->
                            "Invalid request url: " <> url <> " (" <> reason <> ")"

                        HttpExceptionRequest _ exceptionContent ->
                            case exceptionContent of
                                Http.StatusCodeException response _ ->
                                    "Unexpected status code in response from docker-run: " <> (show $ Status.statusCode $ Http.responseStatus response)

                                Http.TooManyRedirects _ ->
                                    "Too many redirect"

                                Http.OverlongHeaders ->
                                    "Header overflow from docker-run"

                                Http.ResponseTimeout ->
                                    "docker-run took too long to return a response"

                                Http.ConnectionTimeout ->
                                    "Attempting to connect to docker-run timed out"

                                Http.ConnectionFailure _ ->
                                    "An exception occurred when trying to connect to docker-run"

                                Http.InvalidStatusLine _ ->
                                    "The status line returned by docker-run could not be parsed"

                                Http.InvalidHeader _ ->
                                    "The given response header line from docker-run could not be parsed"

                                Http.InvalidRequestHeader _ ->
                                    "The given request header is not compliant"

                                Http.InternalException _ ->
                                    "An exception was raised by an underlying library when performing the request"

                                Http.ProxyConnectException _ _ _ ->
                                    "A non-200 status code was returned when trying to connect to the proxy server on the given host and port"

                                Http.NoResponseDataReceived ->
                                    "No response data was received from the docker-run at all"

                                Http.TlsNotSupported ->
                                    "Tls not supported"

                                Http.WrongRequestBodyStreamSize _ _ ->
                                    "The request body provided did not match the expected size."

                                Http.ResponseBodyTooShort _ _ ->
                                    "The returned response body from docker-run is too short"

                                Http.InvalidChunkHeaders ->
                                    "A chunked response body had invalid headers"

                                Http.IncompleteHeaders ->
                                    "An incomplete set of response headers were returned from docker-run"

                                Http.InvalidDestinationHost _ ->
                                    "The host we tried to connect to is invalid"

                                Http.HttpZlibException _ ->
                                    "An exception was thrown when inflating the response body from docker-run"

                                Http.InvalidProxyEnvironmentVariable _ _ ->
                                    "Values in the proxy environment variable were invalid"

                                Http.ConnectionClosed ->
                                    "Attempted to use a Connection which was already closed"

                                Http.InvalidProxySettings _ ->
                                    "Proxy settings are not valid"


        DecodeSuccessResponseError _ decodeError ->
            show decodeError

        DecodeErrorResponseError _ decodeError ->
            show decodeError

        ApiError errorBody ->
            show errorBody
formatError :: Error -> String
formatError err =
    case err of
        ParseUrlError ->
            "Invalid docker-run url"

        HttpException exception ->
            case exception of
                Req.JsonHttpException reason ->
                    "Failed to decode json response from docker-run: " <> reason

                Req.VanillaHttpException httpException ->
                    case httpException of
                        InvalidUrlException url reason ->
                            "Invalid request url: " <> url <> " (" <> reason <> ")"

                        HttpExceptionRequest _ exceptionContent ->
                            case exceptionContent of
                                Http.StatusCodeException response _ ->
                                    "Unexpected status code in response from docker-run: " <> (show $ Status.statusCode $ Http.responseStatus response)

                                Http.TooManyRedirects _ ->
                                    "Too many redirect"

                                Http.OverlongHeaders ->
                                    "Header overflow from docker-run"

                                Http.ResponseTimeout ->
                                    "docker-run took too long to return a response"

                                Http.ConnectionTimeout ->
                                    "Attempting to connect to docker-run timed out"

                                Http.ConnectionFailure _ ->
                                    "An exception occurred when trying to connect to docker-run"

                                Http.InvalidStatusLine _ ->
                                    "The status line returned by docker-run could not be parsed"

                                Http.InvalidHeader _ ->
                                    "The given response header line from docker-run could not be parsed"

                                Http.InvalidRequestHeader _ ->
                                    "The given request header is not compliant"

                                Http.InternalException _ ->
                                    "An exception was raised by an underlying library when performing the request"

                                Http.ProxyConnectException _ _ _ ->
                                    "A non-200 status code was returned when trying to connect to the proxy server on the given host and port"

                                Http.NoResponseDataReceived ->
                                    "No response data was received from the docker-run at all"

                                Http.TlsNotSupported ->
                                    "Tls not supported"

                                Http.WrongRequestBodyStreamSize _ _ ->
                                    "The request body provided did not match the expected size."

                                Http.ResponseBodyTooShort _ _ ->
                                    "The returned response body from docker-run is too short"

                                Http.InvalidChunkHeaders ->
                                    "A chunked response body had invalid headers"

                                Http.IncompleteHeaders ->
                                    "An incomplete set of response headers were returned from docker-run"

                                Http.InvalidDestinationHost _ ->
                                    "The host we tried to connect to is invalid"

                                Http.HttpZlibException _ ->
                                    "An exception was thrown when inflating the response body from docker-run"

                                Http.InvalidProxyEnvironmentVariable _ _ ->
                                    "Values in the proxy environment variable were invalid"

                                Http.ConnectionClosed ->
                                    "Attempted to use a Connection which was already closed"

                                Http.InvalidProxySettings _ ->
                                    "Proxy settings are not valid"


        DecodeSuccessResponseError _ decodeError ->
            show decodeError

        DecodeErrorResponseError _ decodeError ->
            show decodeError

        ApiError errorBody ->
            show errorBody
formatError err =
    case err of
        ParseUrlError ->
            "Invalid docker-run url"

        HttpException exception ->
            case exception of
                Req.JsonHttpException reason ->
                    "Failed to decode json response from docker-run: " <> reason

                Req.VanillaHttpException httpException ->
                    case httpException of
                        InvalidUrlException url reason ->
                            "Invalid request url: " <> url <> " (" <> reason <> ")"

                        HttpExceptionRequest _ exceptionContent ->
                            case exceptionContent of
                                Http.StatusCodeException response _ ->
                                    "Unexpected status code in response from docker-run: " <> (show $ Status.statusCode $ Http.responseStatus response)

                                Http.TooManyRedirects _ ->
                                    "Too many redirect"

                                Http.OverlongHeaders ->
                                    "Header overflow from docker-run"

                                Http.ResponseTimeout ->
                                    "docker-run took too long to return a response"

                                Http.ConnectionTimeout ->
                                    "Attempting to connect to docker-run timed out"

                                Http.ConnectionFailure _ ->
                                    "An exception occurred when trying to connect to docker-run"

                                Http.InvalidStatusLine _ ->
                                    "The status line returned by docker-run could not be parsed"

                                Http.InvalidHeader _ ->
                                    "The given response header line from docker-run could not be parsed"

                                Http.InvalidRequestHeader _ ->
                                    "The given request header is not compliant"

                                Http.InternalException _ ->
                                    "An exception was raised by an underlying library when performing the request"

                                Http.ProxyConnectException _ _ _ ->
                                    "A non-200 status code was returned when trying to connect to the proxy server on the given host and port"

                                Http.NoResponseDataReceived ->
                                    "No response data was received from the docker-run at all"

                                Http.TlsNotSupported ->
                                    "Tls not supported"

                                Http.WrongRequestBodyStreamSize _ _ ->
                                    "The request body provided did not match the expected size."

                                Http.ResponseBodyTooShort _ _ ->
                                    "The returned response body from docker-run is too short"

                                Http.InvalidChunkHeaders ->
                                    "A chunked response body had invalid headers"

                                Http.IncompleteHeaders ->
                                    "An incomplete set of response headers were returned from docker-run"

                                Http.InvalidDestinationHost _ ->
                                    "The host we tried to connect to is invalid"

                                Http.HttpZlibException _ ->
                                    "An exception was thrown when inflating the response body from docker-run"

                                Http.InvalidProxyEnvironmentVariable _ _ ->
                                    "Values in the proxy environment variable were invalid"

                                Http.ConnectionClosed ->
                                    "Attempted to use a Connection which was already closed"

                                Http.InvalidProxySettings _ ->
                                    "Proxy settings are not valid"


        DecodeSuccessResponseError _ decodeError ->
            show decodeError

        DecodeErrorResponseError _ decodeError ->
            show decodeError

        ApiError errorBody ->
            show errorBody