Permalink
Browse files

Added a factory for creating MailChimp specific errors

  • Loading branch information...
1 parent 3b4a642 commit b5c9857e3eb0e941871b10a56ce90395fe61ee7f @gomfunkel committed Aug 9, 2012
Showing with 23 additions and 1 deletion.
  1. +23 −1 lib/mailchimp/helpers.js
View
24 lib/mailchimp/helpers.js
@@ -1,4 +1,4 @@
-/***
+/**
* Recursively encode an object as application/x-www-form-urlencoded.
*
* @param value Value to encode
@@ -31,4 +31,26 @@ var serialize = module.exports.serialize = function (value, key) {
return key + '=' + encodeURIComponent(value);
}
+}
+
+/**
+ * Creates an Error with information received from MailChimp. In addition to an
+ * error message it also includes an error code. A detailed list of known error
+ * messages and codes can be found at the url below for version 1.3 of the API.
+ *
+ * @see http://apidocs.mailchimp.com/api/1.3/exceptions.field.php
+ *
+ * @param message The error message
+ * @param code The error code
+ * @return Instance of {@link Error}
+ */
+var createMailChimpError = module.exports.createMailChimpError = function (message, code) {
+
+ error = new Error(message || (message = ''));
+
+ if (code)
+ error.code = code;
+
+ return error;
+
}

0 comments on commit b5c9857

Please sign in to comment.