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

sometimes crashs with "TypeError: Cannot create property 'statusCode' on...." #82

Open
macrozone opened this issue May 12, 2023 · 6 comments

Comments

@macrozone
Copy link

macrozone commented May 12, 2023

when doing certain requests (currently investigating which one), it sometimes crashes with

/path/to/node_modules/mailchimp-api-v3/index.js:530
 result.statusCode = response.statusCode;


TypeError: Cannot create property 'statusCode' on string '{"members":[{"id":"xxx","email_address":"....."
@prasidhda
Copy link

@macrozone , I am also facing this issue once in a while and it forces to stop the docker container too. Did you find the solution to this?

@macrozone
Copy link
Author

macrozone commented Jun 22, 2023

@macrozone , I am also facing this issue once in a while and it forces to stop the docker container too. Did you find the solution to this?

not yet, i thought it was related to the chunk size, so i lowered the amount of members that i sent to the mailchimp api.

at first i thought it fixed the problem, but that is not the case, it still happens, but unfortunatly not consistently.

I also use meteor so i thought it would be a node-fiber related issue, since the whole thing is in a try-catch but still does not manage to catch this error.

@macrozone
Copy link
Author

it seems because it uses the deprecated request package which has bugs on its own

@macrozone
Copy link
Author

so here is my conclusion:

  • the request package that is used is deprecated and has bugs, it can lead to requests that are not properly finished
  • those requests still will end up with a normal success callback in the request package, but the response.body is then a string and not an object
  • at this line https://github.com/thorning/node-mailchimp/blob/master/index.js#L530 its expected that the request.body is an object, otherwise it tries to assign a property to a string, which does not work and throws an error
  • an error there won't fail the surrounding promise, so you can't catch that.

so here i worked around this problem:

  • i patched this package to reject the promise
diff --git a/index.js b/index.js
index 34f9e2ec2b74b78e1e48945fbd307449839ef4d6..f74c3b2d3a2c15e6ba90d2295323a11aac450b4e 100644
--- a/index.js
+++ b/index.js
@@ -527,6 +527,10 @@ Mailchimp.prototype.request = function (options, done) {
       }
 
       var result = response.body || {};
+      if (typeof result === "string") {
+        reject(new Error("request was cut off"));
+        return;
+      }
       result.statusCode = response.statusCode;
 
       resolve(result)

that way i can at least handle it gracefully.

i then try to retry the request in my application code. The error happens rarley, so on second attempt it usually works

@prasidhda
Copy link

@macrozone , Thanks for the detailed information. I will try to implement your solution.

@macrozone
Copy link
Author

if you have the capacity its best to move away from this library as its not maintained anymore and is based on deprecated packages

Repository owner deleted a comment from tomjrtsmith Feb 23, 2024
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

2 participants