Sha256: ed7423c412a21f0ffd94ed9b4849db1b5e3ce16b05aa47b37f879c2040123bd3

Contents?: true

Size: 1.42 KB

Versions: 6

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

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

6 entries across 6 versions & 1 rubygems

Version Path
universal-git-client-2.2.0 lib/universal-git-client/http/response_validation.rb
universal-git-client-2.1.0 lib/universal-git-client/http/response_validation.rb
universal-git-client-2.0.0 lib/universal-git-client/http/response_validation.rb
universal-git-client-1.2.12 lib/universal-git-client/http/response_validation.rb
universal-git-client-1.2.10 lib/universal-git-client/http/response_validation.rb
universal-git-client-1.2.9 lib/universal-git-client/http/response_validation.rb