From d50ddbb10f08a23186153cfcfe65726a90c25d45 Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Fri, 21 Nov 2014 12:59:48 +0100 Subject: [PATCH] Add more fields to error responses with hint, detail and context for SQL errors. --- NEWS.md | 7 +++++- app/controllers/app.js | 2 ++ app/postgresql/error_handler.js | 8 ++++++ npm-shrinkwrap.json | 43 ++++++++++++++++++++++----------- package.json | 2 +- test/acceptance/app.test.js | 5 +++- 6 files changed, 50 insertions(+), 17 deletions(-) diff --git a/NEWS.md b/NEWS.md index b3817b05..22fc6954 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,7 +1,12 @@ -1.18.1 - 2014-mm-dd +1.19.0 - 2014-mm-dd ------------------- +New features: + + * Add more fields to error responses with hint, detail and context for SQL errors. + Enhancements: + * Don't loop twice over svg rows * Improve statement timeout error messages * Improve topojson output by streaming json diff --git a/app/controllers/app.js b/app/controllers/app.js index e427c51f..013ec6de 100755 --- a/app/controllers/app.js +++ b/app/controllers/app.js @@ -569,6 +569,8 @@ function handleException(err, res) { error: [pgErrorHandler.getMessage()] }; + _.defaults(msg, pgErrorHandler.getFields()); + if (global.settings.environment == 'development') { msg.stack = err.stack; } diff --git a/app/postgresql/error_handler.js b/app/postgresql/error_handler.js index 83b92242..045c2163 100644 --- a/app/postgresql/error_handler.js +++ b/app/postgresql/error_handler.js @@ -23,6 +23,14 @@ ErrorHandler.prototype.getMessage = function() { return message; }; +ErrorHandler.prototype.getFields = function(fields) { + fields = fields || ['detail', 'hint', 'context']; + return fields.reduce(function (previousValue, current) { + previousValue[current] = this.err[current]; + return previousValue; + }.bind(this), {}); +}; + ErrorHandler.prototype.getStatus = function() { var statusError = this.err.http_status || 400; diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 17390ad5..6eb97ad4 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1,6 +1,6 @@ { "name": "cartodb_sql_api", - "version": "1.18.1", + "version": "1.19.0", "dependencies": { "cartodb-psql": { "version": "0.4.0", @@ -61,7 +61,8 @@ }, "nan": { "version": "1.1.2", - "from": "nan@~1.1.0" + "from": "nan@~1.1.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-1.1.2.tgz" } } } @@ -72,42 +73,51 @@ "express": { "version": "2.5.11", "from": "express@~2.5.11", + "resolved": "https://registry.npmjs.org/express/-/express-2.5.11.tgz", "dependencies": { "connect": { "version": "1.9.2", "from": "connect@1.x", + "resolved": "https://registry.npmjs.org/connect/-/connect-1.9.2.tgz", "dependencies": { "formidable": { "version": "1.0.15", - "from": "formidable@1.0.x" + "from": "formidable@1.0.x", + "resolved": "https://registry.npmjs.org/formidable/-/formidable-1.0.15.tgz" } } }, "mime": { "version": "1.2.4", - "from": "mime@1.2.4" + "from": "mime@1.2.4", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.2.4.tgz" }, "qs": { "version": "0.4.2", - "from": "qs@0.4.x" + "from": "qs@0.4.x", + "resolved": "https://registry.npmjs.org/qs/-/qs-0.4.2.tgz" }, "mkdirp": { "version": "0.3.0", - "from": "mkdirp@0.3.0" + "from": "mkdirp@0.3.0", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.0.tgz" } } }, "log4js": { "version": "0.6.21", "from": "log4js@~0.6.18", + "resolved": "https://registry.npmjs.org/log4js/-/log4js-0.6.21.tgz", "dependencies": { "async": { "version": "0.2.10", - "from": "async@~0.2.0" + "from": "async@~0.2.0", + "resolved": "https://registry.npmjs.org/async/-/async-0.2.10.tgz" }, "readable-stream": { - "version": "1.0.33-1", + "version": "1.0.33", "from": "readable-stream@~1.0.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.33.tgz", "dependencies": { "core-util-is": { "version": "1.0.1", @@ -123,7 +133,7 @@ }, "inherits": { "version": "2.0.1", - "from": "inherits@2" + "from": "inherits@~2.0.1" } } }, @@ -136,11 +146,13 @@ }, "lru-cache": { "version": "2.5.0", - "from": "lru-cache@~2.5.0" + "from": "lru-cache@~2.5.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-2.5.0.tgz" }, "node-statsd": { "version": "0.0.7", - "from": "node-statsd@~0.0.7" + "from": "node-statsd@~0.0.7", + "resolved": "https://registry.npmjs.org/node-statsd/-/node-statsd-0.0.7.tgz" }, "oauth-client": { "version": "0.3.0", @@ -149,7 +161,8 @@ "dependencies": { "node-uuid": { "version": "1.1.0", - "from": "node-uuid@1.1.0" + "from": "node-uuid@1.1.0", + "resolved": "https://registry.npmjs.org/node-uuid/-/node-uuid-1.1.0.tgz" } } }, @@ -159,7 +172,8 @@ "dependencies": { "node-uuid": { "version": "1.4.1", - "from": "node-uuid@1.4.x" + "from": "node-uuid@1.4.x", + "resolved": "https://registry.npmjs.org/node-uuid/-/node-uuid-1.4.1.tgz" }, "lru-cache": { "version": "2.2.4", @@ -199,7 +213,8 @@ }, "underscore": { "version": "1.6.0", - "from": "underscore@~1.6.0" + "from": "underscore@~1.6.0", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.6.0.tgz" } } } diff --git a/package.json b/package.json index cb86880e..217d7751 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "keywords": [ "cartodb" ], - "version": "1.18.1", + "version": "1.19.0", "repository": { "type": "git", "url": "git://github.com/CartoDB/CartoDB-SQL-API.git" diff --git a/test/acceptance/app.test.js b/test/acceptance/app.test.js index dcf3dedd..86bc882b 100644 --- a/test/acceptance/app.test.js +++ b/test/acceptance/app.test.js @@ -671,7 +671,10 @@ test('COPY TABLE with GET and auth', function(done){ assert.equal(res.statusCode, 400, res.statusCode + ': ' + res.body); assert.deepEqual(res.headers['content-type'], 'application/json; charset=utf-8'); assert.deepEqual(res.headers['content-disposition'], 'inline'); - assert.deepEqual(JSON.parse(res.body), {"error":["must be superuser to COPY to or from a file"]}); + assert.deepEqual(JSON.parse(res.body), { + error: ["must be superuser to COPY to or from a file"], + hint: "Anyone can COPY to stdout or from stdin. psql's \\copy command also works for anyone." + }); done(); }); });