diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2012-07-14 01:38:33 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2012-07-14 01:38:43 +0200 |
commit | 090295773d12cae88e81cf2e509168ad5e3fda45 (patch) | |
tree | 965eaeff69d93cc68f2299e2f59ec6fb0727bac8 /routes | |
parent | 47b4b51573f240763ee8b761bfe9f37ffce8e0fb (diff) | |
download | example-collection-json-db-090295773d12cae88e81cf2e509168ad5e3fda45.tar.gz example-collection-json-db-090295773d12cae88e81cf2e509168ad5e3fda45.tar.bz2 example-collection-json-db-090295773d12cae88e81cf2e509168ad5e3fda45.tar.xz example-collection-json-db-090295773d12cae88e81cf2e509168ad5e3fda45.zip |
o Improved error handling when postgres fails.
Diffstat (limited to 'routes')
-rw-r--r-- | routes/index.js | 20 |
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)); } |