Module: UniversalGitClient::Http::ResponseValidation

Included in:
Base
Defined in:
lib/universal-git-client/http/response_validation.rb

Instance Method Summary collapse

Instance Method Details

#with_response_validation!Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/universal-git-client/http/response_validation.rb', line 8

def with_response_validation!
  response = yield
  case response.code
  when 200..399 then response
  when 400 then raise Errors::BadRequest.new('BadRequest', response)
  when 401 then raise Errors::Unauthorized.new('Unauthorized', response)
  when 403 then raise Errors::Forbidden.new('Forbidden', response)
  when 404 then raise Errors::NotFound.new('NotFound', response)
  when 405 then raise Errors::MethodNotAllowed.new('MethodNotAllowed', response)
  when 406 then raise Errors::NotAcceptable.new('NotAcceptable', response)
  when 409 then raise Errors::Conflict.new('Conflict', response)
  when 415 then raise Errors::UnsupportedMediaType.new('UnsupportedMediaType', response)
  when 422 then raise Errors::UnprocessableEntity.new('UnprocessableEntity', response)
  when 400..499 then raise Errors::ClientError.new('ClientError', response)
  when 500 then raise Errors::InternalServerError.new('InternalServerError', response)
  when 502 then raise Errors::BadGateway.new('BadGateway', response)
  when 503 then raise Errors::ServiceUnavailable.new('ServiceUnavailable', response)
  when 500..599 then raise Errors::ServerError.new('ServerError', response)
  end
end