Skip to content

Commit

Permalink
fix: missing paths returns 404 instead of 502 (#59)
Browse files Browse the repository at this point in the history
Fixes #53

Co-authored-by: Daniel N <[email protected]>
  • Loading branch information
2color and 2color authored Apr 20, 2024
1 parent 5bb6685 commit 291a054
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/verified-fetch/src/verified-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ export class VerifiedFetch {
terminalElement = pathDetails.terminalElement
} catch (err: any) {
options?.signal?.throwIfAborted()
if (['ERR_NO_PROP', 'ERR_NO_TERMINAL_ELEMENT'].includes(err.code)) {
if (['ERR_NO_PROP', 'ERR_NO_TERMINAL_ELEMENT', 'ERR_NOT_FOUND'].includes(err.code)) {
return notFoundResponse(resource.toString())
}
this.log.error('error walking path %s', path, err)
Expand Down
18 changes: 18 additions & 0 deletions packages/verified-fetch/test/verified-fetch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -838,5 +838,23 @@ describe('@helia/verifed-fetch', () => {
const resp = await verifiedFetch.fetch(`http://example.com/ipfs/${cid}/foo/i-do-not-exist`)
expect(resp.status).to.equal(404)
})

it('returns a 404 when walking dag-pb for non-existent path', async () => {
const fs = unixfs(helia)

const res = await last(fs.addAll([{
path: 'index.html',
content: Uint8Array.from([0x01, 0x02, 0x03])
}], {
wrapWithDirectory: true
}))

if (res == null) {
throw new Error('Import failed')
}

const resp = await verifiedFetch.fetch(`ipfs://${res.cid}/does/not/exist`)
expect(resp.status).to.equal(404)
})
})
})

0 comments on commit 291a054

Please sign in to comment.