Skip to content

Commit cef430d

Browse files
committed
Auto merge of rust-lang#2130 - Turbo87:404, r=locks
mirage/crates: Return 404 if specified crate can't be found Our `GET /api/v1/crates/:id` mirage request handler was not handling unknown crates the same way as the production API server. This PR fixes the inconsistency by returning a 404 error if the client requests a crate that does not exist on the mock server. r? @locks
2 parents 17b3a0b + 30634f7 commit cef430d

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

mirage/route-handlers/crates.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export function register(server) {
3636
server.get('/api/v1/crates/:crate_id', function(schema, request) {
3737
let crateId = request.params.crate_id;
3838
let crate = schema.crates.find(crateId);
39+
if (!crate) return notFound();
40+
3941
let categories = schema.categories.all().filter(category => (crate.categories || []).indexOf(category.id) !== -1);
4042
let keywords = schema.keywords.all().filter(keyword => (crate.keywords || []).indexOf(keyword.id) !== -1);
4143
let versions = schema.versions

0 commit comments

Comments
 (0)