You are viewing a plain text version of this content. The canonical link for it is here.
Posted to devnull@infra.apache.org by "smcgee31 (GitHub)" <gi...@apache.org> on 2018/08/25 16:22:53 UTC

[GitHub] [couchdb-nano] smcgee31 opened issue #118: Using promises only returns body

When I try to run code in a promises type of way, either raw promises or async/await the returned information is only `{ body }`, not `{ err, body, header }`. However, when I write the code as callbacks I do get `{ err, body, header }` as expected.

## Expected Behavior
My understanding is that when I write my code like...
```js
async function saveData(submission) {
  try {
    const result = await myDb.insert(submission);
    return result;
  } catch (error) {
    throw new DatabaseError(error);
  }
}
```
 I should get an object back like...
```json
{
  "err": null,
  "body": {
    "ok": true,
    "id": "14ac5e3dc6f74c19d7f3a0f28946a997",
    "rev": "1-6679afee204060e7893f58ced4ffe89c"
  },
  "header": {
    "uri": "localhost:5984/myDb",
    "statusCode": 201,
    "location": "localhost:5984/myDb/14ac5e3dc6f74c19d7f3a0f28946a997",
    "etag": "\"1-6679afee204060e7893f58ced4ffe89c\"",
    "date": "Sat, 25 Aug 2018 15:55:47 GMT",
    "content-type": "application/json",
    "cache-control": "must-revalidate"
  }
}
```

## Current Behavior
When using promises the returned object is only `body` ...
```json
{
  "ok": true,
  "id": "0ad5b89865ced95aa88142ea1d9c2462",
  "rev": "1-6679afee205010e7893f58ced4cfe79c"
}
```

## Possible Solution
It seems that the information is probably there, just not being included in the return somehow.
(I was going to attempt a PR but when I fork, clone, `npm i`, and run tests I get failing tests and haven't been able to figure out why)

## Your Environment
* Version used: Apache CouchDB 1.6.1
* Browser Name and version: Google Chrome Version 68.0.3440.106 (Official Build) (64-bit)
* Operating System and version (desktop or mobile): macOS High Sierra version 10.13.6 


[ Full content available at: https://github.com/apache/couchdb-nano/issues/118 ]
This message was relayed via gitbox.apache.org for devnull@infra.apache.org

[GitHub] [couchdb-nano] tehnorm commented on issue #118: Using promises only returns body

Posted by "tehnorm (GitHub)" <gi...@apache.org>.
Also having the same challenge. The issue seems to be here:

https://github.com/apache/couchdb-nano/blob/master/lib/nano.js#L115

For the promised based flow the return signature simply doesn't include the `responseHeaders` like the callback based flow: https://github.com/apache/couchdb-nano/blob/master/lib/nano.js#L118

This seems to be an oversight? I can't think of a reason why the two API's should differ?

[ Full content available at: https://github.com/apache/couchdb-nano/issues/118 ]
This message was relayed via gitbox.apache.org for devnull@infra.apache.org