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

isIdempotencyConflict: error combining mailgun-js and gocardless-nodejs #67

Closed
XavierColombel opened this issue Apr 30, 2020 · 2 comments

Comments

@XavierColombel
Copy link

XavierColombel commented Apr 30, 2020

I ran into a bug when I import mailgun-js and gocardless-nodejs libs in the same project.

Here is the error message I got:

(node:62883) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'statusCode' of undefined
    at Api.isIdempotencyConflict (/Users/johndoe/Github/johndoe-admin/node_modules/gocardless-nodejs/api/api.js:125:26)
    at Api.request (/Users/johndoe/Github/johndoe-admin/node_modules/gocardless-nodejs/api/api.js:58:22)
(node:62883) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:62883) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

You need to install 3 libs to reproduce the problem:

npm i mailgun-js gocardless-nodejs cuid

Here is the full code you can use (don't forget to add your GoCardless PRIVATE_API_KEY):

const mailgun = require("mailgun-js");
const constants = require("gocardless-nodejs/constants");
const gocardless = require("gocardless-nodejs");

const cuid = require("cuid");

(async function () {
  const client = gocardless(
    "XXXXXX_PRIVATE_API_KEY_XXXXXX",
    constants.Environments.Sandbox
  );

  const session_token = cuid();
  const redirectFlow = await client.redirectFlows.create({
    description: "my product",
    session_token,
    success_redirect_url:
      "https://anyredirecturl.com`,
    prefilled_customer: {
      given_name: "john",
      family_name: "doe",
      email: "johndoe@domain.com",
      company_name: "JD Company",
      address_line1: "Hi",
      postal_code: "12334",
    },
  });
})();

It might be an error with the got lib GoCardless uses.

@lancscoder
Copy link
Contributor

Hi @XavierColombel,

Thanks for getting in touch.

After looking into this it looks like mailgun-js is using an old version of agent-base (version 4) which is monkey patching https (https://github.com/TooTallNate/node-agent-base/blob/4.3.0/patch-core.js) and this is causing the issue. Any https call that is made will fail, see below example:

var got = require('got');
var mailgun = require('mailgun-js');

(async () => {
  var httpWorking = await got('http://www.google.co.uk');

  console.log(httpWorking);

  var httpsNotWorking = await got('https://www.google.co.uk');

  console.log(httpsNotWorking);
})();

This bug/issue is fixed in agent-base version 5 and above. I'd reach out to the authors of the mailgun-js library and see if they can update their dependencies.

@XavierColombel
Copy link
Author

Thanks @lancscoder . I've switched to Axios request because it seems their mailgun-js lib is not maintained anymore...

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