demarches-normaliennes/app/lib/api_particulier/error.rb
simon lehericey 87cb16093f fetch token introspection
Co-authored-by: François VANTOMME <akarzim@gmail.com>
2021-09-15 14:37:04 +02:00

32 lines
853 B
Ruby

module APIParticulier
module Error
class HttpError < ::StandardError
def initialize(response)
connect_time = response.connect_time
curl_message = response.return_message
http_error_code = response.code
datetime = response.headers.fetch('Date', DateTime.current.inspect)
total_time = response.total_time
uri = URI.parse(response.effective_url)
url = "#{uri.host}#{uri.path}"
msg = <<~TEXT
url: #{url}
HTTP error code: #{http_error_code}
#{response.body}
curl message: #{curl_message}
total time: #{total_time}
connect time: #{connect_time}
datetime: #{datetime}
TEXT
super(msg)
end
end
class RequestFailed < HttpError; end
class Unauthorized < HttpError; end
end
end