keen / keen-analysis.js

A light JavaScript client for Keen
https://keen.io/docs/compute/
MIT License
40 stars 15 forks source link

When not configured correctly, queries still try to run and return a weird error #47

Closed maxpaj closed 5 years ago

maxpaj commented 5 years ago

I accidentally provided empty credentials (undefined) to the constructor of KeenAnalysis. Stupid of me. In any case, the error message I got was really confusing until I found the mistake. Would be nice if the constructor can check the given credentials and throw an error if it fails.

const KeenAnalysis = require("keen-analysis");
const KeenClient = new KeenAnalysis({
  projectId: Config.keen.projectId,   // was undefined
  readKey: Config.keen.readKey        // was undefined
});

The error I got from Keen when using KeenClient.query( ... ):

error: "value" required in setHeader("Authorization", value) {"stack":"Error: \"value\" required in setHeader(\"Authorization\", value)
    at validateHeader (_http_outgoing.js:489:11)
    at ClientRequest.setHeader (_http_outgoing.js:498:3)
    at new ClientRequest (_http_client.js:183:14)
    at Object.request (http.js:38:10)
    at Object.request (https.js:245:15)
    at Object.request (/app/node_modules/agent-base/patch-core.js:23:20)
    at request (/app/node_modules/keen-analysis/dist/node/webpack:/lib/utils/http-server.js:36:21)
    at httpHandler (/app/node_modules/keen-analysis/dist/node/webpack:/lib/request.js:105:27)
    at new Promise (<anonymous>)
    at request.send (/app/node_modules/keen-analysis/dist/node/webpack:/lib/request.js:98:26)
    at request.send (/app/node_modules/keen-analysis/dist/node/webpack:/lib/request.js:40:17)
    at Client.post [as query] (/app/node_modules/keen-analysis/dist/node/webpack:/lib/index.js:104:8)
adamkasprowicz commented 5 years ago

Hi @maxpaj , Thank you for reporting! I've just added this issue to our backlog. I think in the long term we will choose the same route as Webpack did - to validate not only the values, but also to check the property names (for typos etc). PS: 🍔 are delicious!

maxpaj commented 5 years ago

@adamkasprowicz nice! Thanks dude!

apryka commented 5 years ago

implemented in v3.4.0