client-js icon indicating copy to clipboard operation
client-js copied to clipboard

noticing the JS api does not surface errors verbosely

Open rrshaban opened this issue 9 months ago • 2 comments

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.

rrshaban avatar Jun 01 '24 00:06 rrshaban