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:

  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."
  case 'StripeInvalidRequestError':
    // Invalid parameters were supplied to Stripe's API
  case 'StripeAPIError':
    // An error occurred internally with Stripe's API
  case 'StripeConnectionError':
    // Some kind of error occurred during the HTTPS communication
  case 'StripeAuthenticationError':
    // You probably used an incorrect API key
  case 'StripeRateLimitError':
    // Too many requests hit the API too quickly
You can’t perform that action at this time.