VulcanJS / Vulcan

🌋 A toolkit to quickly build apps with React, GraphQL & Meteor
http://vulcanjs.org
MIT License
7.98k stars 1.88k forks source link

Newsletter package: createError requires a "message" property on the config object passed as the second parameter #1957

Closed bernardodiasc closed 6 years ago

bernardodiasc commented 6 years ago

Hi folks, using the Newsletter module, the functionality works well.

But found one problem when trying to force an error, like subscribing an existing email, the response only gives me createError requires a "message" property on the config object passed as the second parameter.

Here’s the server log:

I20180418-13:56:36.426(-3)? { Error: myemail@gmail.com is already subscribed to the list.
I20180418-13:56:36.427(-3)?     at module.exports.createMailChimpError (/Users/website/node_modules/mailchimp/lib/mailchimp/helpers.js:49:14)
I20180418-13:56:36.427(-3)?     at Object.module.exports.handleMailChimpResponse (/Users/website/node_modules/mailchimp/lib/mailchimp/helpers.js:81:21)
I20180418-13:56:36.428(-3)?     at Request._callback (/Users/website/node_modules/mailchimp/lib/mailchimp/MailChimpAPI_v2_0.js:59:11)
I20180418-13:56:36.428(-3)?     at Request.self.callback (/Users/website/node_modules/request/request.js:186:22)
I20180418-13:56:36.428(-3)?     at emitTwo (events.js:126:13)
I20180418-13:56:36.428(-3)?     at Request.emit (events.js:214:7)
I20180418-13:56:36.429(-3)?     at Request.<anonymous> (/Users/website/node_modules/request/request.js:1163:10)
I20180418-13:56:36.429(-3)?     at emitOne (events.js:116:13)
I20180418-13:56:36.429(-3)?     at Request.emit (events.js:211:7)
I20180418-13:56:36.429(-3)?     at Gunzip.<anonymous> (/Users/website/node_modules/request/request.js:1085:12)
I20180418-13:56:36.430(-3)?     at Object.onceWrapper (events.js:313:30)
I20180418-13:56:36.430(-3)?     at emitNone (events.js:111:20)
I20180418-13:56:36.430(-3)?     at Gunzip.emit (events.js:208:7)
I20180418-13:56:36.431(-3)?     at endReadableNT (_stream_readable.js:1055:12)
I20180418-13:56:36.431(-3)?     at _combinedTickCallback (internal/process/next_tick.js:138:11)
I20180418-13:56:36.431(-3)?     at process._tickDomainCallback (internal/process/next_tick.js:218:9) code: 214 }
W20180418-13:56:36.476(-3)? (STDERR) AssertionError [ERR_ASSERTION]: createError requires a "message" property on the config object passed as the second parameter
W20180418-13:56:36.477(-3)? (STDERR)     at exports.createError (/Users/website/node_modules/apollo-errors/dist/index.js:68:5)
W20180418-13:56:36.477(-3)? (STDERR)     at Object.subscribe (packages/vulcan:newsletter/lib/server/integrations/mailchimp.js:62:33)
W20180418-13:56:36.478(-3)? (STDERR)     at Collection.Newsletters.subscribeUser (packages/vulcan:newsletter/lib/server/newsletters.js:47:40)
W20180418-13:56:36.478(-3)? (STDERR)     at addUserNewsletter (packages/vulcan:newsletter/lib/server/mutations.js:31:26)
W20180418-13:56:36.478(-3)? (STDERR)     at field.resolve (/Users/website/node_modules/graphql-extensions/lib/index.js:119:77)
W20180418-13:56:36.478(-3)? (STDERR)     at resolveFieldValueOrError (/Users/website/node_modules/graphql/execution/execute.js:501:12)
W20180418-13:56:36.479(-3)? (STDERR)     at resolveField (/Users/website/node_modules/graphql/execution/execute.js:465:16)
W20180418-13:56:36.479(-3)? (STDERR)     at /Users/website/node_modules/graphql/execution/execute.js:287:20
W20180418-13:56:36.479(-3)? (STDERR)     at /Users/bernardo/.meteor/packages/promise/.0.10.2.jluu88.jxvn++os+web.browser+web.cordova/npm/node_modules/meteor-promise/fiber_pool.js:43:40

I’m currently using the intl to format text, but graphQLError don’t have a name prop to use.

const message = this.context.intl.formatMessage({id: `newsletter.error_${graphQLError.name}`}, {message: graphQLError.message});

Checking on the Vulcan package I noticed that message is empty for that error case: https://github.com/VulcanJS/Vulcan/blob/devel/packages/vulcan-newsletter/lib/server/integrations/mailchimp.js#L54-L61

bernardodiasc commented 6 years ago

Tested on v1.9.1 and the bug no longer occurs.

Can see it's fixed here https://github.com/VulcanJS/Vulcan/commit/800784f3f9cda58a6e960095aa4910872f1b009a#diff-5cf875fb5003a01655fbd454fbc3280e 👏

Thanks @SachaG!