Promise not sending any data. No error?

53 Views Asked by At

When this promise is run the browser just times out ( didn’t send any data. ERR_EMPTY_RESPONSE). There aren't any errors in the terminal. The first console.log is printed but nothing else.

var createStripeCustomer = function(customer, source) {
    console.log('create stripe customer');
    return new Promise(function(res, rej) {
        stripe.customers.create({
            email: customer.email,
            source: source,
            account_balance: 500,
            metadata: {
                first_name: customer.first_name,
                last_name: customer.last_name,
                phone: customer.phone,
                address: `${customer.address} ${customer.appt}`,
                city: customer.city,
                state: customer.state,
                zipcode: customer.zip,
                referral: customer.referral
            },
            function(err, newCustomer) {
                if (err) {
                    console.log(err);
                    rej(err);
                }
                else {
                    console.log('created customer');
                    res(newCustomer);
                }
            }
        });
    });
};
1

There are 1 best solutions below

1
On BEST ANSWER

You have missed a } in the stripe.customers.create method first parameter:

var createStripeCustomer = function(customer, source) {
    console.log('create stripe customer');
    return new Promise(function(res, rej) {
        stripe.customers.create({
            email: customer.email,
            source: source,
            account_balance: 500,
            metadata: {
                first_name: customer.first_name,
                last_name: customer.last_name,
                phone: customer.phone,
                address: `${customer.address} ${customer.appt}`,
                city: customer.city,
                state: customer.state,
                zipcode: customer.zip,
                referral: customer.referral
             }
            },
            function(err, newCustomer) {
                if (err) {
                    console.log(err);
                    rej(err);
                }
                else {
                    console.log('created customer');
                    res(newCustomer);
                }
            }
        });
    });
};

and then it should work in this way:

createStripeCustomer(customer, source).then( res => console.log(res) ).catch(error => console.error(error))