nano
nano copied to clipboard
error object not properly formatted
On a db.get with an invalid doc Id, the error returned is not properly formatted.
couch.db.get(id, { revs_info: true }, function(err, body) {
if (err) {
debug(err);
......
......
});
The error object looks like this:
{ [Error: missing]
name: 'Error',
error: 'not_found',
reason: 'missing',
scope: 'couch',
statusCode: 404,
request:
{ method: 'GET',
headers:
{ 'content-type': 'application/json',
accept: 'application/json' },
uri: 'http://couchhost:5984/db/tsp2',
qs: { revs_info: true } },
headers:
{ date: 'Thu, 17 Mar 2016 19:23:40 GMT',
'content-type': 'application/json',
'cache-control': 'must-revalidate',
statusCode: 404,
uri: 'http://couchhost:5984/db/tsp2' },
errid: 'non_200',
description: 'couch returned 404' }
I saw in one of the examples references to the error object like the following, where the error object seems to have a message and a 'status-code' property:
db.get('foo', function (error, body, headers) {
if(error) { return response.send(error.message, error['status-code']); }
Please advise.
I get the same malformed error messages (here is example of attempting to create database that exists):
nano.db.create('testdb', function(err, body) {
if (err) {
console.log(err);
}
});
{ [Error: The database could not be created, the file already exists.]
name: 'Error',
error: 'file_exists',
reason: 'The database could not be created, the file already exists.',
scope: 'couch',
statusCode: 412,
request:
{ method: 'PUT',
headers:
{ 'content-type': 'application/json',
accept: 'application/json' },
uri: 'http://localhost:5984/testdb' },
headers:
{ date: 'Thu, 28 Apr 2016 17:04:59 GMT',
'content-type': 'application/json',
'cache-control': 'must-revalidate',
statusCode: 412,
uri: 'http://localhost:5984/testdb' },
errid: 'non_200',
description: 'couch returned 412' }
When done with curl: curl -X PUT http://localhost:5984/testdb | json_pp
:
{
"error" : "file_exists",
"reason" : "The database could not be created, the file already exists."
}
It seems this is a console.log
and/or NodeJS thing (I'm new, sorry!). console.log(err.toString())
formats it properly, though I'm still not sure why the error message came out so awkwardly before.
Hi @jcferrer and @cboden, my impression is that the nano documentation is out of date. The 'status-code' property no longer exists, and it has been replaced by 'statusCode'. I filed issue #328 for this.
Regarding the 'message' propery, I think that property is output like [Error:
I see this issue was filed a couple months ago, so you've likely moved on, but does this reply address your question?
It seems that this question has been answered, if so could you close this issue?