lib/backchat_client/http_client.rb
# This method is used to handle the HTTP response
# *response* HTTP response
# *request* HTTP request
# *result*
This method is used to handle the HTTP response
response* HTTP response
request* HTTP request
result
This method is used to handle the HTTP response response * HTTP response request * HTTP request result
def response_handler(response, request, result, &block)
      case response.code
      when 200..207
        response.return!(request, result, &block)
      when 301..307
        response.follow_redirection(request, result, &block)
      when 400
        logger.warn("Bad request")
        logger.warn("#{result.code} => #{result.message}")
        raise BackchatClient::Error::ClientError.new(result)
      when 401
        logger.warn("Error while accessing Backchat. Authentication failed")
        logger.warn("#{result.code} => #{result.message}")
        raise BackchatClient::Error::ClientError.new(result)
      when 404
        logger.warn("Error while accessing Backchat. Resource not found")
        logger.warn("#{result.code} => #{result.message}")
        raise BackchatClient::Error::ClientError.new(result)
      when 409
        logger.warn("Error while accessing Backchat. Conflict")
        logger.warn("#{result.code} => #{result.message}")
        raise BackchatClient::Error::ConflictError.new(result)
      when 422
        logger.warn("Error while accessing Backchat. Unprocessable entity")
        logger.warn("#{result.code} => #{result.message}")
        raise BackchatClient::Error::UnprocessableError.new(result)
      when 402..408,410..421,423..499
        logger.warn("Error while accessing Backchat")
        logger.warn("#{result.code} => #{result.message}")
        response.return!(request, result, &block)
      when 500..599
        logger.warn("Error while accessing Backchat")
        logger.warn("#{result.code} => #{result.message}")
        raise BackchatClient::Error::ServerError.new(result)
      else
        logger.warn("Error while accessing Backchat")
        logger.warn("#{result.code} => #{result.message}")
        response.return!(request, result, &block)
      end
    end
def response_handler ( response , request , result , & block ) case response . code when 200 .. 207 response . return! ( request , result , & block ) when 301 .. 307 response . follow_redirection ( request , result , & block ) when 400 logger . warn ( "Bad request" ) logger . warn ( "#{result.code} => #{result.message}" ) raise BackchatClient :: Error :: ClientError . new ( result ) when 401 logger . warn ( "Error while accessing Backchat. Authentication failed" ) logger . warn ( "#{result.code} => #{result.message}" ) raise BackchatClient :: Error :: ClientError . new ( result ) when 404 logger . warn ( "Error while accessing Backchat. Resource not found" ) logger . warn ( "#{result.code} => #{result.message}" ) raise BackchatClient :: Error :: ClientError . new ( result ) when 409 logger . warn ( "Error while accessing Backchat. Conflict" ) logger . warn ( "#{result.code} => #{result.message}" ) raise BackchatClient :: Error :: ConflictError . new ( result ) when 422 logger . warn ( "Error while accessing Backchat. Unprocessable entity" ) logger . warn ( "#{result.code} => #{result.message}" ) raise BackchatClient :: Error :: UnprocessableError . new ( result ) when 402 .. 408 , 410 .. 421 , 423 .. 499 logger . warn ( "Error while accessing Backchat" ) logger . warn ( "#{result.code} => #{result.message}" ) response . return! ( request , result , & block ) when 500 .. 599 logger . warn ( "Error while accessing Backchat" ) logger . warn ( "#{result.code} => #{result.message}" ) raise BackchatClient :: Error :: ServerError . new ( result ) else logger . warn ( "Error while accessing Backchat" ) logger . warn ( "#{result.code} => #{result.message}" ) response . return! ( request , result , & block ) end end
This method is used to handle the HTTP response
response* HTTP response
request* HTTP request
result
This method is used to handle the HTTP response response * HTTP response request * HTTP request result
# If there is a :location header, return it
response
<not_specific>
request
<not_specific>
result
<not_specific>
block
<not_specific>