1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
defmodule ExOvh.ResponseError do
@moduledoc :false
defexception [:conn]
def exception([conn: %HTTPipe.Conn{} = conn]) do
%ExOvh.ResponseError{conn: conn}
end
def message(%ExOvh.ResponseError{conn: conn}) do
~s"""
The following http connection execution was unsuccessful, unexpected or erroneous in some way:
Request Details:
"""
<>
request_output(conn)
<>
"\nResponse Details:\n"
<>
response_output(conn)
end
def request_output(conn) do
~s"""
** Request Method **
#{Kernel.inspect(conn.request.method)}
** Request Body **
#{Kernel.inspect conn.request.body}
** Request Headers **
#{Kernel.inspect(conn.request.headers)}
** Request Url **
#{Kernel.inspect(conn.request.url)}
"""
end
def response_output(conn) do
~s"""
** Reponse Status Code **
#{Kernel.inspect conn.response.status_code}
** Response Body **
#{Kernel.inspect(conn.response.body)}
** Response Headers **
#{Kernel.inspect(conn.response.headers)}
"""
end
end