Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Status resolve/reject #282

Open
davidretireup opened this issue Nov 3, 2021 · 0 comments
Open

Status resolve/reject #282

davidretireup opened this issue Nov 3, 2021 · 0 comments

Comments

@davidretireup
Copy link

davidretireup commented Nov 3, 2021

The handling of 400 level statusCodes via error callback or reject is not backward compatible after 9.0.1 (due to changes in axios somewhere around 0.21.1)

Expected Behavior

In the following code example, if a database does not exist when using nano 9.0.1 or earlier, exists would be true if missing_db does not exist:

const {db} = require('nano')({
    url: 'http://some-db.server.com:5984/',
    parseUrl: false
})
const exists = await db.get('missing_db')
    .then(() => true)
    .catch(err => err.statusCode === 404 ? false : Promise.reject(err))

Current Behavior

The above example code rejects with err as:

 {
     message: 'error happened in your connection',
     scope: 'socket',
     errid: 'request'
 }

Possible Solution

The following change to the config object corrects the issue, as a workaround:

 const {db} = require('nano')({
     url: 'http://some-db.server.com:5984/',
     parseUrl: false,
     requestDefaults: {
         validateStatus: status => status < 500 // Resolve only if the status code is less than 500
     }
 })

Steps to Reproduce (for bugs)

  1. Ensure missing_db does not exist
  2. Execute the example code

Context

It is necessary to be able to know if a database exists or not

Your Environment

  • Version used: nano 9.0.5
  • Browser Name and version:
  • Operating System and version (desktop or mobile): node on MacOS
  • Link to your project:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant