Skip to content

Commit 16e5279

Browse files
committed
mirage: Fix README status codes
We are serving these files via S3, which unfortunately returns 403 instead of 404 for missing files...
1 parent e22c684 commit 16e5279

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

mirage/route-handlers/crates.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,12 +374,12 @@ export function register(server) {
374374
const { name, version: versionNum } = request.params;
375375
const crate = schema.crates.findBy({ name });
376376
if (!crate) {
377-
return new Response(404, { 'Content-Type': 'text/html' }, '');
377+
return new Response(403, { 'Content-Type': 'text/html' }, '');
378378
}
379379

380380
const version = schema.versions.findBy({ crateId: crate.id, num: versionNum });
381381
if (!version || !version.readme) {
382-
return new Response(404, { 'Content-Type': 'text/html' }, '');
382+
return new Response(403, { 'Content-Type': 'text/html' }, '');
383383
}
384384

385385
return new Response(200, { 'Content-Type': 'text/html' }, version.readme);

tests/mirage/crates/versions/readme-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ module('Mirage | GET /api/v1/crates/:id/:version/readme', function (hooks) {
1111

1212
test('returns 404 for unknown crates', async function (assert) {
1313
let response = await fetch('/api/v1/crates/foo/1.0.0/readme');
14-
assert.strictEqual(response.status, 404);
14+
assert.strictEqual(response.status, 403);
1515
assert.strictEqual(await response.text(), '');
1616
});
1717

1818
test('returns 404 for unknown versions', async function (assert) {
1919
this.server.create('crate', { name: 'rand' });
2020

2121
let response = await fetch('/api/v1/crates/rand/1.0.0/readme');
22-
assert.strictEqual(response.status, 404);
22+
assert.strictEqual(response.status, 403);
2323
assert.strictEqual(await response.text(), '');
2424
});
2525

@@ -28,7 +28,7 @@ module('Mirage | GET /api/v1/crates/:id/:version/readme', function (hooks) {
2828
this.server.create('version', { crate, num: '1.0.0' });
2929

3030
let response = await fetch('/api/v1/crates/rand/1.0.0/readme');
31-
assert.strictEqual(response.status, 404);
31+
assert.strictEqual(response.status, 403);
3232
assert.strictEqual(await response.text(), '');
3333
});
3434

0 commit comments

Comments
 (0)