Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Algosdk fails parsing JSON from error response when there is no JSON data in the response. #582

Open
ashleydavis opened this issue Jun 6, 2022 · 0 comments
Labels
new-bug Bug report that needs triage Team Lamprey

Comments

@ashleydavis
Copy link

Subject of the issue

Algosdk fails parsing JSON from error response when there is no JSON data in the response.

Steps to reproduce

It's difficult to reproduce but I can show you exactly where the problem is.

Expected behaviour

My sandbox is returning a 504 status code from this route algod/v2/transactions/params.

When calling algoClient.getTransactionParams().do() it should print a reasonable error message.

Actual behaviour

Algosdk attempts to parse JSON data from the error response when there is no JSON data resulting in the following unreasonable error message:

SyntaxError: Unexpected token E in JSON at position 0
    at JSON.parse (<anonymous>)
    at Function.parseJSON (client.ts:125:8)
    at Function.prepareResponse (client.ts:187:12)
    at Function.prepareResponseError (client.ts:209:33)
    at HTTPClient.get (client.js:186:30)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

The attempt to parse JSON is made here:

return text && utils.parseJSON(text, jsonOptions);

The problem originates from this request here:

const res = await this.bc.get(

When the sandbox has a problem (for me it is status 504 at the moment) it throws an error with no JSON in the response which is handled here:

const res = await this.bc.get(

It tries to parse the response from err.response which is not JSON so it throws the aforementioned error.

@ashleydavis ashleydavis added the new-bug Bug report that needs triage label Jun 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-bug Bug report that needs triage Team Lamprey
Projects
None yet
Development

No branches or pull requests

3 participants
@winder @ashleydavis and others