Skip to content

Error Handling

James Byrne edited this page Nov 25, 2016 · 4 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 'StripeInvalidRequestError':
    // 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;
  case 'StripeRateLimitError':
    // Too many requests hit the API too quickly
    break;
}
You can’t perform that action at this time.