sendwithus / sendwithus_nodejs

Sendwithus NodeJS Client
https://www.sendwithus.com
Apache License 2.0
22 stars 17 forks source link

Cannot read property 'ok' of undefined in sendwithus.js #64

Closed thomasInes closed 1 year ago

thomasInes commented 1 year ago

Hi,

does the API have an issue this morning? The library has started to throw errors in our app. It seems the API is not sending what the library expects (cf error below). We didn't observe this behavior with this version of the library before. Thank you :)

Client version

6.0.1

Expected behaviour

no error thrown

Actual behaviour

error being thrown by the library:

{
    "errorType": "Runtime.UnhandledPromiseRejection",
    "errorMessage": "TypeError: Cannot read property 'ok' of undefined",
    "reason": {
        "errorType": "TypeError",
        "errorMessage": "Cannot read property 'ok' of undefined",
        "stack": [
            "TypeError: Cannot read property 'ok' of undefined",
            "    at Sendwithus._handleResponse (/var/task/node_modules/sendwithus/lib/sendwithus.js:122:23)",
            "    at /var/task/node_modules/sendwithus/lib/sendwithus.js:91:63",
            "    at propagateAslWrapper (/var/task/node_modules/async-listener/index.js:504:23)",
            "    at proxyWrapper (/var/task/node_modules/async-listener/index.js:531:16)",
            "    at /var/task/node_modules/async-listener/index.js:541:70",
            "    at /var/task/node_modules/async-listener/glue.js:188:31",
            "    at processTicksAndRejections (internal/process/task_queues.js:97:5)"
        ]
    },
    "promise": {},
    "stack": [
        "Runtime.UnhandledPromiseRejection: TypeError: Cannot read property 'ok' of undefined",
        "    at process.<anonymous> (/var/runtime/index.js:35:15)",
        "    at process.emit (events.js:314:20)",
        "    at process.EventEmitter.emit (domain.js:483:12)",
        "    at processPromiseRejections (internal/process/promises.js:209:33)",
        "    at processTicksAndRejections (internal/process/task_queues.js:98:32)"
    ]
}

Steps to reproduce

not sure. either calling send or render

demoore commented 1 year ago

Hmm, this could be a result of an issue on the API or network issue, but I think something else is going on. We're taking a look. Thanks for reporting this!

thomasInes commented 1 year ago

@demoore thanks for looking into this. FWI, if that can help, the emails related to these calls seem to have been processed and sent successfully by SWU.

edit: Please ignore. Our app has a retry mechanism. The emails were processed succesfully on the 2nd call

demoore commented 1 year ago

No worries @thomasInes! We appreciate the report :smile:

v6.0.2 was just pushed to npm if you want to give that a shot: https://www.npmjs.com/package/sendwithus

thomasInes commented 1 year ago

Thank you @demoore. Will upgrade and monitor the lib's behavior.

Just out of curiosity though, if the issue is network or API related, how would your update help? And if it not, should it not means the lib should error out all the time? In our case it errors out randomly (but more frequently these past few days). Just trying to understand. Thanks again

demoore commented 1 year ago

I don't think it's network related. I was able to reproduce the same error with some pretty basic code:

api.render({ template: TEMPLATE_ID }, (r) => {
  console.log(r); // this worked
  console.log(Object.keys(r)); // this did NOT
});

I think this was happening in specific cases where the render/send callback was trying to access the response object. Without seeing your code it's tough to say for sure -- especially since we didn't have any API alarms go off.

Keep me posted on whether the issue persists! If so, we might have to get you to reach out to our support so we can trace your account.

thomasInes commented 1 year ago

Thank you. Will keep you posted