Skip to content

Enhancement: ApiError JSON parsing #12

Description

@jaredmoody

The response_body field of the ApiError class is always a string - but sometimes it's a JSON string, and sometimes not.

So, to extract a meaningful error message i have to do something like:

message = 
  if error.response_headers['Content-Type'].include?('application/json')
    JSON.parse(error.response_body).dig('message')
  else
    error.response_body
  end

It seems parsing the response from the API should be a concern of the ApiError Class, what do you think about adding something that does this to the ApiError class? I'm happy to submit a PR if you like the idea.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions