Permalink
Browse files

Added test and doc

  • Loading branch information...
1 parent 8077a2d commit b6a22a55c4c91a1bdbcaf638e3d2f7e26e37b364 @gflandre gflandre committed Jan 28, 2013
Showing with 28 additions and 2 deletions.
  1. +2 −2 README.md
  2. +26 −0 test/errors.js
View
@@ -17,7 +17,7 @@ Access to the [Stripe](https://stripe.com/) [API](https://stripe.com/docs/api).
{ email: 'foobar@example.org' },
function(err, customer) {
if (err) {
- console.log("Couldn't create the customer record");
+ console.log(err.message);
return;
}
console.log("customer id", customer.id);
@@ -28,7 +28,7 @@ Access to the [Stripe](https://stripe.com/) [API](https://stripe.com/docs/api).
## API
All methods takes a callback as their last parameter. The callback is
-called with an error code (if any) and then the response.
+called with a Javascript `Error` (if any) and then the response.
* `stripe.charges` - create, retrieve, refund and list charges
* `.create(charge)` - [create a charge](https://stripe.com/docs/api#create_charge)
View
@@ -0,0 +1,26 @@
+var vows = require('vows'),
+ assert = require('assert'),
+ sys = require('sys');
+
+var api_key = process.env.STRIPE_API;
+
+if (!api_key) {
+ sys.puts('To run vows, you must have a STRIPE_API environment variable with a test api key');
+ process.exit(2)
+}
+
+var stripe = require('./../lib/main.js')(api_key);
+
+vows.describe("Error handling").addBatch({
+ 'Retrieve non-existing plan' : {
+ topic: function() {
+ stripe.plans.retrieve("unknown_plan_" + Date.now(), this.callback);
+ },
+ 'returns an error' : function(err, response) {
+ assert.isNull(response);
+ assert.instanceOf(err, Error);
+ assert.equal(err.name, 'invalid_request_error');
+ assert.isNotNull(err.message);
+ },
+ },
+}).export(module, {error: false});

0 comments on commit b6a22a5

Please sign in to comment.