opsgenie / opsgenie-nodejs-sdk

OpsGenie Node.js SDK
https://www.opsgenie.com/docs/api-and-client-libraries/opsgenie-nodejs-api
Apache License 2.0
25 stars 19 forks source link

Alerts V2 callback receives a string response instead of an object #8

Closed bakatz closed 7 years ago

bakatz commented 7 years ago

The following code prints: "string"

opsgenie.alertV2.list(activeAlertsParams, function (error, alerts) {
    if(!error) console.log(typeof(alerts))
}

This is mildly annoying because, in order to reference any properties on alerts, I have to manually call JSON.parse(alerts) myself

Shouldn't the callback be called with the result obtained from JSON.parse(...) instead of just passing the raw response string to the callback?

EDIT: also, my package.json includes this version of the SDK - "opsgenie-sdk": "^0.4.1"

serhatcan commented 7 years ago

I believe we are parsing, not sure why this happened. Please see this line where we parse the response body: https://github.com/opsgenie/opsgenie-nodejs-sdk/blob/4a0bf1300278b3ed1f5e00d18813ef2885108dca/lib/restApi.js#L131 I'll let the team know and check this, thanks.

bakatz commented 7 years ago

Yep, I saw that line in the source code myself which is why I was confused. No problem

brksfsrt commented 7 years ago

It's fixed and merged to master. We will publish the new version to the npm as soon as possible.