Module: GdsApi::ExceptionHandling
- Included in:
- JsonClient, Panopticon
- Defined in:
- lib/gds_api/exceptions.rb
Instance Method Summary collapse
- #build_specific_http_error(error, url, details = nil, request_body = nil) ⇒ Object
- #error_class_for_code(code) ⇒ Object
- #ignoring(exception_or_exceptions, &block) ⇒ Object
- #ignoring_missing(&block) ⇒ Object
Instance Method Details
#build_specific_http_error(error, url, details = nil, request_body = nil) ⇒ Object
62 63 64 65 66 |
# File 'lib/gds_api/exceptions.rb', line 62 def build_specific_http_error(error, url, details = nil, request_body = nil) = "URL: #{url}\nResponse body:\n#{error.http_body}\n\nRequest body:\n#{request_body}" code = error.http_code error_class_for_code(code).new(code, , details) end |
#error_class_for_code(code) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/gds_api/exceptions.rb', line 68 def error_class_for_code(code) case code when 401 GdsApi::HTTPUnauthorized when 403 GdsApi::HTTPForbidden when 404 GdsApi::HTTPNotFound when 409 GdsApi::HTTPConflict when 410 GdsApi::HTTPGone when 422 GdsApi::HTTPUnprocessableEntity when (400..499) GdsApi::HTTPClientError when (500..599) GdsApi::HTTPServerError else GdsApi::HTTPErrorResponse end end |
#ignoring(exception_or_exceptions, &block) ⇒ Object
52 53 54 55 56 |
# File 'lib/gds_api/exceptions.rb', line 52 def ignoring(exception_or_exceptions, &block) yield rescue *exception_or_exceptions # Discard the exception end |
#ignoring_missing(&block) ⇒ Object
58 59 60 |
# File 'lib/gds_api/exceptions.rb', line 58 def ignoring_missing(&block) ignoring([HTTPNotFound, HTTPGone], &block) end |