Skip to content

Commit

Permalink
Add 400 error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jemgold committed Mar 20, 2014
1 parent 7d8ac20 commit ef1a733
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/littleprinter.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ littleprinter.edition = function(req, res) {

littleprinter.handler.edition(localDeliveryTime, deliveryCount, other, function(e, data) {
if(e) {
if (e === 400) {
return res.send(400);
}
return res.send(500);
}

Expand Down Expand Up @@ -100,4 +103,4 @@ littleprinter.createEtag = function(s) {
return hash.digest('hex');
};

module.exports = littleprinter;
module.exports = littleprinter;
7 changes: 6 additions & 1 deletion test/littleprinter_edition_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ describe('using littleprinter', function() {
littleprinter.edition(req, res);
assert(littleprinter.handler.edition.withArgs('LDT', 'DC', req.query).calledOnce);
});
it('should return 400 if handler says so', function() {
littleprinter.handler.edition.yields(400);
littleprinter.edition(req, res);
assert(res.send.withArgs(400).calledOnce);
});
it('should return 500 if handler errors', function() {
littleprinter.handler.edition.yields('ERROR');
littleprinter.edition(req , res);
Expand Down Expand Up @@ -76,4 +81,4 @@ describe('using littleprinter', function() {
assert.equal(res.send.firstCall.args[0], '304');
});
});
});
});

0 comments on commit ef1a733

Please sign in to comment.