Callback requests send 200 status error even if the query failed

This commit is contained in:
Raul Ochoa 2014-08-04 15:56:43 +02:00
parent 78c5bcde21
commit ce70e7252b
2 changed files with 27 additions and 6 deletions

View File

@ -560,18 +560,24 @@ function handleException(err, res){
res.header('X-SQLAPI-Profiler', res.req.profiler.toJSONString());
}
// if the exception defines a http status code, use that, else a 400
if (!_.isUndefined(err.http_status)){
res.send(msg, err.http_status);
} else {
res.send(msg, 400);
}
res.send(msg, getStatusError(err, res.req));
if ( res.req && res.req.profiler ) {
res.req.profiler.sendStats();
}
}
function getStatusError(err, req) {
var statusError = _.isUndefined(err.http_status) ? 400 : err.http_status;
// JSONP has to return 200 status error
if (req && req.query && req.query.callback) {
statusError = 200;
}
return statusError;
}
return app;
}

View File

@ -1421,4 +1421,19 @@ test('GET with callback param returns wrapped result set with callback as jsonp'
});
});
test('GET with callback must return 200 status error even if it is an error', function(done){
assert.response(app, {
url: "/api/v1/sql?q=DROP%20TABLE%20untitle_table_4&callback=foo_jsonp",
headers: {host: 'vizzuality.cartodb.com'},
method: 'GET'
},{}, function(res) {
assert.equal(res.statusCode, 200, res.statusCode + ': ' + res.body);
function foo_jsonp(body) {
assert.deepEqual(body, {"error":["must be owner of relation untitle_table_4"]});
}
eval(res.body);
done();
});
});
});