Skip to content

Commit

Permalink
Errors should be returned as json bodies
Browse files Browse the repository at this point in the history
For consistency with a successful response, an error response should
also be in json to allow for the same code in the client app to handle
both cases

closes #4
  • Loading branch information
mrenvoize authored and coce committed Mar 12, 2015
1 parent a1e77d3 commit 2489d7b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions app.js
Expand Up @@ -13,7 +13,9 @@ var isbnRE = /([0-9X]{10,13})/;
app.get('/cover', function(req, res) {
var ids = req.query.id;
if (ids === undefined || ids.length < 8) {
res.send("id parameter is missing");
var fail = {};
fail.error = "ID parameter is missing";
res.send(fail);
return;
}
ids = ids.split(',');
Expand All @@ -27,7 +29,12 @@ app.get('/cover', function(req, res) {
}
}
ids = idsNew;
if (ids.length === 0) { res.send('No id parameter'); return; }
if (ids.length === 0) {
var fail = {};
fail.error = "Bad id parameter";
res.send(fail);
return;
}
var providers = req.query.provider;
providers = providers == undefined ? coce.config.providers : providers.split(',');
var callback = req.query.callback;
Expand Down

0 comments on commit 2489d7b

Please sign in to comment.