Sha256: d707d7401947b2dfbb1ceecf85eb9da4d28c6a364c0d53c2287fc54deecd23a6

Contents?: true

Size: 1.39 KB

Versions: 1

Compression:

Stored size: 1.39 KB

Contents

require 'universal-git-client/errors'

module UniversalGitClient
  module Http
    module ResponseValidation
      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
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
universal-git-client-1.2.4 lib/universal-git-client/http/response_validation.rb