Module: GdsApi::ExceptionHandling

Included in:
JsonClient
Defined in:
lib/gds_api/exceptions.rb

Instance Method Summary collapse

Instance Method Details

#build_specific_http_error(error, url, details = nil) ⇒ Object



73
74
75
76
77
# File 'lib/gds_api/exceptions.rb', line 73

def build_specific_http_error(error, url, details = nil)
  message = "URL: #{url}\nResponse body:\n#{error.http_body}"
  code = error.http_code
  error_class_for_code(code).new(code, message, details, error.http_body)
end

#error_class_for_code(code) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/gds_api/exceptions.rb', line 79

def error_class_for_code(code)
  case code
  when 400
    GdsApi::HTTPBadRequest
  when 401
    GdsApi::HTTPUnauthorized
  when 403
    GdsApi::HTTPForbidden
  when 404
    GdsApi::HTTPNotFound
  when 409
    GdsApi::HTTPConflict
  when 410
    GdsApi::HTTPGone
  when 413
    GdsApi::HTTPPayloadTooLarge
  when 422
    GdsApi::HTTPUnprocessableEntity
  when 429
    GdsApi::HTTPTooManyRequests
  when (400..499)
    GdsApi::HTTPClientError
  when 500
    GdsApi::HTTPInternalServerError
  when 502
    GdsApi::HTTPBadGateway
  when 503
    GdsApi::HTTPUnavailable
  when 504
    GdsApi::HTTPGatewayTimeout
  when (500..599)
    GdsApi::HTTPServerError
  else
    GdsApi::HTTPErrorResponse
  end
end