Skip to content

inconsistent naming of methods 'code' vs 'http_code' (RestClient::Response vs RestClient::ExceptionWithResponse ) #816

@rempargo

Description

@rempargo

I find it inconsistent that a normal response and an exception response don't use the same method name to get the status code.

A normal response has a method called code for the status code, and an exception response got method named 'http_code`.

Maybe there is a reason for this, but I would like to see an alias named code for the http_code method in the ExceptionResponse, so it is less inconsistent.

    begin
        response = RestClient::Request.execute(method: :get, url: "https://www.google.com")
    rescue
        RestClient::ExceptionWithResponse => response
    end
    # response.code       => 200
    # response.http_code  => NoMethodError (undefined method `http_code' for <RestClient::Response 200 "<!doctype h...">:RestClient::Response)


    begin
        response = RestClient::Request.execute(method: :get, url: "https://www.google.com/404")
    rescue 
        RestClient::ExceptionWithResponse => response
    end
    # response.code       => # NoMethodError (undefined method `code' for #<RestClient::NotFound: 404 Not Found>)
    # response.http_code  => 404

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions