fresh icon indicating copy to clipboard operation
fresh copied to clipboard

feat(server): disable 404 response

Open deer opened this issue 1 year ago • 4 comments

closes https://github.com/denoland/fresh/issues/1918

@harrysolovay, what do you think of this? This change allows you to do something like this:

export default defineConfig({
  router: {
    disabled404response: () => {
      throw new Error("my custom error");
    },
  },
});

or

export default defineConfig({
  router: {
    disabled404response: () => {
      return new Response("asdf");
    },
  },
});

I can look to see what it would take to allow just returning undefined, but that seems like a larger change.

deer avatar Nov 08 '23 20:11 deer

No feedback from the requester, so I'll just mark this as ready and see what happens. I'm totally open to reworking this, if desired.

deer avatar Dec 05 '23 23:12 deer

Apologies I haven't had time to give an appropriate review. TBH I don't believe I'd be the right reviewer. Not familiar with the codebase.

harrysolovay avatar Dec 06 '23 00:12 harrysolovay

@harrysolovay, sorry for the miscommunication. All I was looking for was whether the interface of the config is acceptable to you. I know you were hoping for returning undefined, but I thought perhaps a configurable function allowing you to return whatever error you want would possibly be acceptable.

deer avatar Dec 06 '23 09:12 deer

I suppose it's an improvement over needing to create a dedicated 404 route file. Still, I believe getting back a Response | undefined from the render fn would be preferable.

harrysolovay avatar Dec 06 '23 19:12 harrysolovay