Skip to content

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

Open

Description

@mooyg

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

Activity

  1. sahilgupta88 commented on Jul 16, 2024

    @sahilgupta88

    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)

  2. yorihaput commented on Jun 2, 2026

    @yorihaput

    I think
    this issue still open?

    I got same issue when use this library

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

    this happend when there is no connectify from Axios to the server API, can we fix this to remove normalizeError when catch the error from axios?

    Image

    or maybe if there is no response, throw the real error, not normalized error in function normalizeError

    Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions