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) ⇒ Object
- #ignoring(exception_or_exceptions, &block) ⇒ Object
- #ignoring_missing(&block) ⇒ Object
Instance Method Details
#build_specific_http_error(error, url, details = nil) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/gds_api/exceptions.rb', line 55 def build_specific_http_error(error, url, details = nil) = "url: #{url}\n#{error.http_body}" code = error.http_code case code when 403 GdsApi::HTTPForbidden.new(code, , details) when 404 GdsApi::HTTPNotFound.new(code, , details) when 410 GdsApi::HTTPGone.new(code, , details) when 409 GdsApi::HTTPConflict.new(code, , details) when (400..499) GdsApi::HTTPClientError.new(code, , details) when (500..599) GdsApi::HTTPServerError.new(code, , details) else GdsApi::HTTPErrorResponse.new(code, , details) end end |
#ignoring(exception_or_exceptions, &block) ⇒ Object
45 46 47 48 49 |
# File 'lib/gds_api/exceptions.rb', line 45 def ignoring(exception_or_exceptions, &block) yield rescue *exception_or_exceptions # Discard the exception end |
#ignoring_missing(&block) ⇒ Object
51 52 53 |
# File 'lib/gds_api/exceptions.rb', line 51 def ignoring_missing(&block) ignoring([HTTPNotFound, HTTPGone], &block) end |