Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

sanitized callbacks

  • Loading branch information...
commit be70d403b9628a67628e6db9f5f10e4f6c0cb40b 1 parent 1a94ee3
@pdfcrowd authored
Showing with 29 additions and 0 deletions.
  1. +29 −0 lib/pdfcrowd.js
View
29 lib/pdfcrowd.js
@@ -17,6 +17,7 @@ var Pdfcrowd = function(username, apikey) {
Pdfcrowd.prototype.convertHtml = function(html, callbacks, options) {
+ callbacks = prepareCallbacks(callbacks);
requestQueue.addRequest([this, html, '/api/pdf/convert/html/', callbacks, options]);
}
@@ -38,10 +39,37 @@ Pdfcrowd.prototype.convertFile = function(fname, callbacks, options) {
module.exports = Pdfcrowd;
+
+
+
// ---------------------------------------------------------------------------
// private
+var prepareCallbacks = function(callbacks) {
+ callbacks = callbacks || {};
+ if (typeof callbacks.pdf !== "function") {
+ callbacks.pdf = function(rstream) {
+ rstream.destroy();
+ console.warn('WARNING: [Pdfcrowd] Unhandled PDF generation.');
+ };
+ }
+
+ if (typeof callbacks.error !== "function") {
+ callbacks.error = function(errMessage, statusCode) {
+ console.warn("WARNING: [Pdfcrowd] Unhandled error: %d - %s", statusCode, errMessage);
+ };
+ }
+
+ if (typeof callbacks.end !== "function") {
+ callbacks.end = function() {};
+ }
+
+ return callbacks;
+}
+
+
+
var convertInternal = function(that, src, endpoint, callbacks, options) {
// form POST data
@@ -98,6 +126,7 @@ var convertInternal = function(that, src, endpoint, callbacks, options) {
}
+
var requestQueue = {
init: function() {
this.queue = [];
Please sign in to comment.
Something went wrong with that request. Please try again.