Permalink
Browse files

view: handle unpublished packages properly

  • Loading branch information...
1 parent b4aeabe commit 2241a09c843669c70633c399ce698cec3add40b3 @isaacs isaacs committed Apr 13, 2014
Showing with 17 additions and 5 deletions.
  1. +4 −3 lib/utils/error-handler.js
  2. +13 −2 lib/view.js
View
7 lib/utils/error-handler.js
@@ -146,9 +146,10 @@ function errorHandler (er) {
case "E404":
er.code = "E404"
+ var msg = [er.message]
if (er.pkgid && er.pkgid !== "-") {
- var msg = ["'"+er.pkgid+"' is not in the npm registry."
- ,"You should bug the author to publish it"]
+ msg.push("", "'"+er.pkgid+"' is not in the npm registry."
+ ,"You should bug the author to publish it")
if (er.parent) {
msg.push("It was specified as a dependency of '"+er.parent+"'")
}
@@ -161,8 +162,8 @@ function errorHandler (er) {
}
msg.push("\nNote that you can also install from a"
,"tarball, folder, or http url, or git url.")
- log.error("404", msg.join("\n"))
}
+ log.error("404", msg.join("\n"))
break
case "EPUBLISHCONFLICT":
View
15 lib/view.js
@@ -61,10 +61,21 @@ function view (args, silent, cb) {
if (data["dist-tags"] && data["dist-tags"].hasOwnProperty(version)) {
version = data["dist-tags"][version]
}
+
+ if (data.time && data.time.unpublished) {
+ var u = data.time.unpublished
+ var er = new Error("Unpublished by " + u.name + " on " + u.time)
+ er.statusCode = 404
+ er.code = "E404"
+ er.pkgid = data._id
+ return cb(er, data)
+ }
+
+
var results = []
, error = null
- , versions = data.versions
- data.versions = Object.keys(data.versions).sort(semver.compareLoose)
+ , versions = data.versions || {}
+ data.versions = Object.keys(versions).sort(semver.compareLoose)
if (!args.length) args = [""]
// remove readme unless we asked for it

0 comments on commit 2241a09

Please sign in to comment.