Module: Alula::Dcp::ErrorHandler

Overview

DCP Error Handler

Instance Method Summary collapse

Instance Method Details

#handle_errors(response) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/alula/dcp/error_handler.rb', line 7

def handle_errors(response)
  case response.http_status
  when 300..399
    # Should never see a 300-range response code
    raise Alula::UnknownError,
          "The Alula-Ruby gem encountered a response code of #{response.http_status}, that should not happen"
  when 500..599
    # Server errors, malformed data, etc
    AlulaError.for_response(response)
  when 400..499
    # Validation errors usually
    model_errors = Util.model_errors_from_dcp_response(response)
    return AlulaError.for_response(response) unless model_errors

    annotate_errors(model_errors)
    false
  else
    raise Alula::UnknownError, "Unknown HTTP response code, aborting. Code: #{response.http_status}"
  end
end