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



55
56
57
58
59
# File 'lib/gds_api/exceptions.rb', line 55

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)
end

#error_class_for_code(code) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/gds_api/exceptions.rb', line 61

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 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