Suppress remix ErrorResponseImpl
errors
#8933
-
I am running remix from an express server with nodejs When a route is not found, I see in the console:
I have the following code in my export function handleError(
error: any,
{ request, params, context }: LoaderFunctionArgs | ActionFunctionArgs
) {
if (!request.signal.aborted && !error.data?.includes("No route matches URL")) {
logger.error(
{
err: extractError(error),
},
"unhandled remix error"
)
}
} and call remix from express like app.all("*", createRequestHandler({ build: build as any })) Previously, setting NODE_ENV=production stopped this output, but it seems that either something else stopped it previously or it has come back. Full code available here https://github.com/danthegoodman1/NodeExpressRemixTemplate How can I stop these logs? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Here's a robust solution that handles bots and random traffic while avoiding unnecessary server responses.
// app/$.jsx
import { json } from '@remix-run/node';
const NotImplementedError = () => new Response(null, {
status: 501,
statusText: 'NotImplemented'
});
const NotFoundError = () => json({
error: 'NotFound',
}, {
status: 404,
});
// handle baddies
export function action() {
throw NotImplementedError();
}
// throw a json response to raise our root error boundary
export function loader() {
throw NotFoundError();
}
export default function Index() {
return null;
}
// app/root.jsx
import { useRouteError, isRouteErrorResponse } from 'react-router-dom';
...
export function ErrorBoundary() {
const err = useRouteError();
// return status text for anything that isn't 404,
// otherwise show the NotFound component (or w/e you want to do)
if (isRouteErrorResponse(err) && err.status !== 404) {
return err.statusText;
}
return (
<html>
<head>
<title>Not Found</title>
<meta charSet='utf-8' />
<Meta />
<Links />
</head>
<body>
<NotFound/>
<Scripts />
</body>
</html>
);
} |
Beta Was this translation helpful? Give feedback.
Here's a robust solution that handles bots and random traffic while avoiding unnecessary server responses.