Module: ApiAdaptor::ExceptionHandling
- Included in:
- JsonClient
- Defined in:
- lib/api_adaptor/exceptions.rb
Overview
Module providing HTTP error handling and exception mapping
Instance Method Summary collapse
-
#build_specific_http_error(error, url, details = nil) ⇒ HTTPErrorResponse
private
Builds a specific HTTP error exception based on the status code.
-
#error_class_for_code(code) ⇒ Class
private
Maps HTTP status codes to exception classes.
Instance Method Details
#build_specific_http_error(error, url, details = nil) ⇒ HTTPErrorResponse
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Builds a specific HTTP error exception based on the status code
126 127 128 129 130 |
# File 'lib/api_adaptor/exceptions.rb', line 126 def build_specific_http_error(error, url, details = nil) = "URL: #{url}\nResponse body:\n#{error.http_body}" code = error.http_code error_class_for_code(code).new(code, , details, error.http_body) end |
#error_class_for_code(code) ⇒ Class
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Maps HTTP status codes to exception classes
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/api_adaptor/exceptions.rb', line 139 def error_class_for_code(code) case code when 400 ApiAdaptor::HTTPBadRequest when 401 ApiAdaptor:: when 403 ApiAdaptor::HTTPForbidden when 404 ApiAdaptor::HTTPNotFound when 409 ApiAdaptor::HTTPConflict when 410 ApiAdaptor::HTTPGone when 413 ApiAdaptor::HTTPPayloadTooLarge when 422 ApiAdaptor::HTTPUnprocessableEntity when 429 ApiAdaptor::HTTPTooManyRequests when (400..499) ApiAdaptor::HTTPClientError when 500 ApiAdaptor::HTTPInternalServerError when 502 ApiAdaptor::HTTPBadGateway when 503 ApiAdaptor::HTTPUnavailable when 504 ApiAdaptor::HTTPGatewayTimeout when (500..599) ApiAdaptor::HTTPServerError else ApiAdaptor::HTTPErrorResponse end end |