Skip to content

Add details on errors #32

@GCorbel

Description

@GCorbel

When a follow request with an invalid ID is sent, this body is returned :

{
    "errors" => [
        {
            "parameters" => {
                "target_user_id" => [
                    "1"
                ]
            },
               "message" => "You cannot unfollow an account that is not active."
        }
    ],
     "title" => "Invalid Request",
    "detail" => "One or more parameters to your request was invalid.",
      "type" => "https://api.twitter.com/2/problems/invalid-request"
}

With the gem, X::BadRequest#message gives : "Invalid Request: One or more parameters to your request was invalid.". As it's more accurate, the message should probably be "Invalid Request: You cannot unfollow an account that is not active.".

Maybe HTTPError#message_from_json_response can be changed to take errors attribute before "title" and "detail". ATM, we can retrieve details with JSON.parse(error.response.body) but it's not very convenient. If the error message is not changed, maybe a method "details" can be added.

Not that, if the gem is changed to take "errors" attribute first, a request with an invalid parameter return this payload

{
    "errors" => [
        {
            "parameters" => {
                "$.text" => [
                    "81462"
                ]
            },
               "message" => "$.text: integer found, string expected"
        }
    ],
     "title" => "Invalid Request",
    "detail" => "One or more parameters to your request was invalid.",
      "type" => "https://api.twitter.com/2/problems/invalid-request"
}

So the error message will be "Invalid Request: $.text: integer found, string expected" which is not formatted to be directly displayed to end users.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions