aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--routes/index.js20
1 files changed, 18 insertions, 2 deletions
diff --git a/routes/index.js b/routes/index.js
index 82bce70..30f0f9b 100644
--- a/routes/index.js
+++ b/routes/index.js
@@ -64,8 +64,24 @@ function after(res, callback) {
return function() {
var err = arguments[0];
if(err) {
- res.writeHead(500, {'Content-Type' : 'text/plain'});
- return res.end('Error! ' + util.inspect(err))
+ // Ideally we would be able to differenciate between
+ // client and server errors, but I'm lazy. It might be
+ // possible to map some values from
+ // http://www.postgresql.org/docs/9.0/static/errcodes-appendix.html
+ // - trygvis
+ var body = JSON.stringify({ collection: {
+ error: {
+ title: 'Unable to insert employee.',
+ message: err.message,
+ code: err.code
+ }
+ }});
+ var headers = {
+ 'Content-Type' : 'application/vnd.collection+json',
+ 'Content-Length' : body.length
+ }
+ res.writeHead(400, headers);
+ return res.end(body);
}
callback.apply(this, _.rest(arguments));
}