Skip to content
This repository has been archived by the owner on Nov 5, 2018. It is now read-only.

error object not properly formatted #317

Open
jcferrer opened this issue Mar 17, 2016 · 4 comments
Open

error object not properly formatted #317

jcferrer opened this issue Mar 17, 2016 · 4 comments

Comments

@jcferrer
Copy link

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.

@cboden
Copy link

cboden commented Apr 28, 2016

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."
}

@cboden
Copy link

cboden commented Apr 28, 2016

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.

@pmanijak
Copy link
Contributor

pmanijak commented May 9, 2016

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: ] by Node.js, so nano is ok there.

I see this issue was filed a couple months ago, so you've likely moved on, but does this reply address your question?

@carlosduclos
Copy link

It seems that this question has been answered, if so could you close this issue?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants