Permalink
Browse files

Error conditions are checked before calling the API.

  • Loading branch information...
1 parent 712d9b5 commit e75a36b6a6ff3980805e29d6888353d5a7a66be3 @pdfcrowd committed Jul 5, 2012
Showing with 9 additions and 2 deletions.
  1. +3 −0 lib/pdfcrowd.js
  2. +6 −2 test/client_test.js
View
3 lib/pdfcrowd.js
@@ -19,6 +19,7 @@ var Pdfcrowd = function(username, apikey) {
// Converts raw HTML code
//
Pdfcrowd.prototype.convertHtml = function(html, callbacks, options) {
+ if (!html) throw 'convertHtml: zero size HTML document.';
requestQueue.addRequest([this, {
src: html,
endpoint: '/api/pdf/convert/html/',
@@ -32,6 +33,7 @@ Pdfcrowd.prototype.convertHtml = function(html, callbacks, options) {
// Converts a web page
//
Pdfcrowd.prototype.convertURI = function(uri, callbacks, options) {
+ if (!uri) throw 'convertURI: invalid URL.';
requestQueue.addRequest([this, {
src: uri,
endpoint: '/api/pdf/convert/uri/',
@@ -48,6 +50,7 @@ Pdfcrowd.prototype.convertFile = function(fname, callbacks, options) {
var that = this;
fs.readFile(fname, function(err, data) {
if (err) throw err;
+ if (!data) throw "convertFile: " + fname + " has zero size"
requestQueue.addRequest([that, {
fname: fname,
data: data.toString('binary'),
View
8 test/client_test.js
@@ -1,18 +1,22 @@
var pdf = require('../lib/pdfcrowd');
+var assert = require('assert');
credentials = require('./config').Credentials;
myPdfcrowd = new pdf.Pdfcrowd(credentials.username,
credentials.apikey);
-var apiOptions = {
+var apiOptions = {
width: "11in",
height: "8.5in",
vmargin: ".4in",
footer_html: '<div style=text-align:center;font-size:smaller;color:maroon;">\
Page %p out of %n\
</div>'
-}
+};
+
+assert.throws(function() { myPdfcrowd.convertHtml(""); });
+assert.throws(function() { myPdfcrowd.convertURI(null); });
myPdfcrowd.convertFile("sample.html.zip", pdf.saveToFile("zfile.pdf"), apiOptions);
myPdfcrowd.convertHtml("raw code", pdf.saveToFile("html.pdf"));

0 comments on commit e75a36b

Please sign in to comment.