module GdsApi::ExceptionHandling

def build_specific_http_error(error, url, details = nil, request_body = nil)

def build_specific_http_error(error, url, details = nil, request_body = nil)
  message = "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, message, details)
end

def error_class_for_code(code)

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

def ignoring(exception_or_exceptions)

def ignoring(exception_or_exceptions)
  yield
rescue *exception_or_exceptions
  # Discard the exception
  nil
end

def ignoring_missing(&block)

def ignoring_missing(&block)
  ignoring([HTTPNotFound, HTTPGone], &block)
end