mirror of
https://github.com/verdaccio/verdaccio.git
synced 2025-03-25 02:32:52 -05:00
Make 404 responses compatible with CouchDB API
The CouchDB REST API returns always `"error": "not_found"` in the body of a 404 response: http://couchdb-13.readthedocs.org/en/latest/api-basics/#http-status-codes The npm client depends on the magic string 'not_found' as can be seen in requestDone() in npm-registry-client/lib/request.js. Before this change, npm install of an unknown package was reporting the Sinopia error string and a stack trace of npm. After this change, npm install of an unknown package returns a nice error saying "the package is not in the npm registry, bug the author"
This commit is contained in:
parent
234deb4e7e
commit
dabf5e1c9a
1 changed files with 9 additions and 1 deletions
10
lib/index.js
10
lib/index.js
|
@ -64,7 +64,15 @@ module.exports = function(config_hash) {
|
|||
if (err.status && err.status >= 400 && err.status < 600) {
|
||||
if (calls == 1) {
|
||||
res.status(err.status)
|
||||
res.send({error: err.msg || err.message || 'unknown error'})
|
||||
var body = {error: err.msg || err.message || 'unknown error'};
|
||||
|
||||
// Make 404 responses compliant with CouchDB REST API
|
||||
if (err.status == 404) {
|
||||
body.reason = body.error
|
||||
body.error = 'not_found'
|
||||
}
|
||||
|
||||
res.send(body)
|
||||
}
|
||||
} else {
|
||||
Logger.logger.error({err: err}, 'unexpected error: @{!err.message}\n@{err.stack}')
|
||||
|
|
Loading…
Add table
Reference in a new issue