Skip to content

Error Handling

makeusabrew edited this page Oct 11, 2014 · 8 revisions

An error is only thrown when you don't pass a required argument to a resource method. All REST or otherwise asynchronous errors will be available as the first argument of any Stripe method's callback:

stripe.customers.create({...}, function(err, result) {});

Or in the form of a rejected promise:

stripe.customers.create({...}).then(
  function(result) {},
  function(err) {}
);

The error object you receive will have one of the following types:

switch (err.type) {
  case 'StripeCardError':
    // A declined card error
    err.message; // => e.g. "Your card's expiration year is invalid."
    break;
  case 'StripeInvalidRequest':
    // Invalid parameters were supplied to Stripe's API
    break;
  case 'StripeAPIError':
    // An error occurred internally with Stripe's API
    break;
  case 'StripeConnectionError':
    // Some kind of error occurred during the HTTPS communication
    break;
  case 'StripeAuthenticationError':
    // You probably used an incorrect API key
    break;
}

Clone this wiki locally