ipfs / helia-verified-fetch

A fetch-like API for obtaining verified & trustless IPFS CIDs on the web
https://npmjs.com/package/@helia/verified-fetch
Other
11 stars 1 forks source link

Missing paths should 404 #53

Closed achingbrain closed 2 months ago

achingbrain commented 2 months ago

When requesting paths that don't exist, the Response is returned as a 502, we should check for the ERR_NOT_FOUND .code property and translate that into a 404.

  helia:verified-fetch:error error walking path icons/favicon-16x16.png Error: file does not exist
    at unixFsResolver (file:///Users/alex/Documents/Workspaces/ipfs/helia-http-gateway-sessions/node_modules/ipfs-unixfs-exporter/dist/src/resolvers/unixfs-v1/index.js:56:27)
    at async walkPath (file:///Users/alex/Documents/Workspaces/ipfs/helia-http-gateway-sessions/node_modules/ipfs-unixfs-exporter/dist/src/index.js:107:24)
    at async walkPath (file:///Users/alex/Documents/Workspaces/ipfs/helia-http-gateway-sessions/node_modules/@helia/verified-fetch/dist/src/utils/walk-path.js:6:22)
    at async VerifiedFetch.handleDagPb (file:///Users/alex/Documents/Workspaces/ipfs/helia-http-gateway-sessions/node_modules/@helia/verified-fetch/dist/src/verified-fetch.js:271:33)
    at async VerifiedFetch.fetch (file:///Users/alex/Documents/Workspaces/ipfs/helia-http-gateway-sessions/node_modules/@helia/verified-fetch/dist/src/verified-fetch.js:495:24)
    at async fetch (file:///Users/alex/Documents/Workspaces/ipfs/helia-http-gateway-sessions/dist/src/helia-http-gateway.js:68:22)
    at async Object.handler (file:///Users/alex/Documents/Workspaces/ipfs/helia-http-gateway-sessions/dist/src/helia-http-gateway.js:144:21) {
  code: 'ERR_NOT_FOUND'
} +10ms

It may just need adding to this array:

https://github.com/ipfs/helia-verified-fetch/blob/f5299cf60c6e964d1b86d50a947812c9d7d18279/packages/verified-fetch/src/verified-fetch.ts#L322