Status resolve/reject
- Dominant language
- JavaScript
- Stars
- 689
- Forks
- 167
- Avg merge
- 1h
- Merged PRs (30d)
- 1
Description
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
3.
4.
## 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:
Contributor guide
Research direction
Reproduce the issue with the provided db.get('missing_db') example and inspect how requestDefaults.validateStatus affects statusCode handling in the request and error paths. Done means a missing database exposes statusCode 404 so the catch returns false, while other errors still reject normally.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100