Skip to content

When Chargify sends a specific error, we may return a JSON parse error instead #7

@natevw

Description

@natevw

When trying to run the tests after updating dependencies, I discovered that Chargify's API is kind of broken. For example, when one doesn't have valid API token, Chargify return a response like:

status: '401 Unauthorized',
'content-type': 'application/json; charset=utf-8',
body: 'HTTP Basic: Access denied.\n',

But regardless because Chargify claims this is "application/json" we try to parse it as JSON and so the resulting error is just something like:

 Uncaught SyntaxError: Unexpected token H in JSON at position 0

instead of something more related to the 401 which would be more helpful.

I wonder if older versions of the request module used to flag non-2xx responses like this as an err to our callback? Or if this is a temporary bug on Chargify's side?

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