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

Promise rejection without error in instance.orders.create() #385

Open
mooyg opened this issue Oct 30, 2023 · 1 comment
Open

Promise rejection without error in instance.orders.create() #385

mooyg opened this issue Oct 30, 2023 · 1 comment

Comments

@mooyg
Copy link

mooyg commented Oct 30, 2023

Steps to reproduce the behavior

try {
        const response = await razorpay.orders.create({
          amount: amount * 100,
          currency: "INR",
        });
        return {
          amount: response.amount,
          currency: response.currency,
          orderId: response.id,
        };
      } catch (e) {
        console.log(e);
        throw new TRPCError({
          code: "INTERNAL_SERVER_ERROR",
        });
      }
  `(node:15211) Warning: a promise was rejected with a non-error: [object Object]`
  Logging the error returns `{ statusCode: undefined, error: undefined }`.

Expected behavior

Should return the error if there is any.

Actual behavior

Sometimes the promise resolves itself without any error and sometimes it doesn't.

Code snippets

No response

Node version

v20.8.0

Library version

razorpay 2.9.2

Additional Information

No response

@sahilgupta88
Copy link

Im facing the similar error, it doesnot work on the first click but subsequent clicks work fine:

` const razorpay = new Razorpay({
key_id: req.body.keyId,
key_secret: req.body.KeySecret,
});

// setting up options for razorpay order.
const options = {
	amount: req.body.amount,
	currency: req.body.currency,
	receipt: 'receipt_' + new Date().getTime(),
	notes: {},
	//payment_capture: 1,
};
console.log(options);
try {
	const response = await razorpay.orders.create(options);
	console.log('Response:', response);
	// Now you can access the `response` object and its properties
	if (response.status === 'created') {
		// Handle the successful order creation
		res.json({
			razor_order_id: response.id,
			currency: response.currency,
			amount: response.amount,
		});
	} else {
		throw Error('Order Cancelled');
	}
} catch (err) {
	console.log(err);
	res.status(400).send(err);
}`

Error:

TypeError: Cannot read properties of undefined (reading 'status')
[0] at normalizeError (/node_modules/razorpay/dist/api.js:40:30)

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