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

noticing the JS api does not surface errors verbosely #194

Open
rrshaban opened this issue Jun 1, 2024 · 2 comments
Open

noticing the JS api does not surface errors verbosely #194

rrshaban opened this issue Jun 1, 2024 · 2 comments
Assignees

Comments

@rrshaban
Copy link

rrshaban commented Jun 1, 2024

const { restClient } = require('@polygon.io/client-js');
const rest = restClient("API KEY"); // actual code


rest.stocks.aggregates("AAPL", 1, "day", "2023-01-01", "2019-04-14").then((data) => {
	console.log(data);
}).catch(e => {
	console.error('An error happened:', e);
});

// last trade
rest.stocks.lastTrade("AAPL").then((data) => {
	console.log(data);
}).catch(e => {
	console.error('An error happened:', e);
});

// last quote (NBBO)
rest.stocks.lastQuote("AAPL").then((data) => {
	console.log(data);
}).catch(e => {
	console.error('An error happened:', e);
});


rest.stocks.snapshotAllTickers().then((data) => {
	console.log(data);
}).catch(e => {
	console.error('An error happened:', e);
});

(all of the above copy-paste from https://polygon.io/blog/javascript-stock-market-data)

% node p.js 
(node:1180) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
An error happened: T [Error]
    at u (/Users/razishaban/node_modules/@polygon.io/client-js/dist/main.cjs:1:1802)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  status: 'ERROR',
  request_id: 'bfeffa1a352ccd1d57303d10ca6002cb'
}
An error happened: T [Error]
    at u (/Users/razishaban/node_modules/@polygon.io/client-js/dist/main.cjs:1:1802)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  status: 'ERROR',
  request_id: 'd0470057a66487a9cd9a93c957cb6246'
}
An error happened: T [Error]
    at u (/Users/razishaban/node_modules/@polygon.io/client-js/dist/main.cjs:1:1802)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  status: 'ERROR',
  request_id: '7c98b5a795d7ad732cb5e3822da65ff7'
}
An error happened: T [Error]
    at u (/Users/razishaban/node_modules/@polygon.io/client-js/dist/main.cjs:1:1802)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  status: 'ERROR',
  request_id: 'ceffc82fc1a9dcffe5b6197c09a64ece'
}

It would be lovely if "T [Error]" offered some kind of ... error type . or message. as it is, the error was No api key, but how could I know?

noting that when I do add the ApiKey, I get 400s and 403... hmm...

NB: having tried 4 of the tutorials now, none of them seem to be "working as-is" with the beginner (Free) api key.

@justinpolygon justinpolygon self-assigned this Jun 1, 2024
@justinpolygon
Copy link
Contributor

justinpolygon commented Jun 1, 2024

Thanks @rrshaban. I noticed you were over in the client-go did you check out the examples in https://github.com/polygon-io/client-go/tree/master/rest/example? The readme in all the repos should work correctly. For example, the client-go one does https://github.com/polygon-io/client-go/tree/master.

I'll update the tutorials on the website to match since they have drifted over time. All the repos should be correct. On this repo, and the client-go, and client-python repos, can you enable tracing via https://github.com/polygon-io/client-go/tree/master and that will show you all the errors. It's the same concept but different syntax for each repo.

Also, what you're likely bumping up against is the 5 api call rate limit for the free tier.

@peterrogov
Copy link

I've been having the same issue. It appears that error handling code in the library is not matching the response structure from the API.

This line in the client core tries to use json.message to get the error message.

error = new StructuredError(json.message, json.status, json.request_id);

However, according to the error response I am seeing in Postman, the correct field name to use is error

{
    "status": "ERROR",
    "request_id": "34f62761c946c5c8592b0fb35a6e156a",
    "error": "You've exceeded the maximum requests per minute, please wait or upgrade your subscription to continue. https://polygon.io/pricing"
}

Also, it would have been extremely helpful to have the HTTP response status code passed into StructuredError too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants