While migrating a page from Fresh v1 to v2-alpha, I noticed that the handler stopped working for what was previously _404 in the new _error.
The issue seems to stem from using the objectMethod type of handler over just a function for GET:
export const handler = define.handlers({
GET(ctx) {
// Return 404 with no HTML body if URL looks to be file-like
const is404 = ctx.error instanceof HttpError && ctx.error.status === 404;
const isFileLike = fileExtensions.some((ext) => ctx.url.pathname.endsWith(ext));
if (is404 && isFileLike) return new Response('', { status: 404, statusText: 'Not found' });
return page();
}
});
// When changed to the below style it started working:
export const handler = define.handlers((ctx) => {
// Same method body
});
There are two "FIXME"'s in the code that is most likely the cause of this issue:
Solution
A quick fix would be to log a warning until the issue is fixed.
- Should
_404 support any other handler types than GET?
- Does
_500/_error support methods other than GET?
While migrating a page from Fresh v1 to v2-alpha, I noticed that the
handlerstopped working for what was previously_404in the new_error.The issue seems to stem from using the objectMethod type of handler over just a
functionforGET:There are two "FIXME"'s in the code that is most likely the cause of this issue:
Solution
A quick fix would be to log a warning until the issue is fixed.
_404support any other handler types thanGET?_500/_errorsupport methods other thanGET?