error()
error() stops a page or partial render by throwing a MiniFW HTTP error. Its status must be a safe integer in the 400 through 599 range.
Expected HTTP Failures
import { error } from "@calvinbonner/minifw/helpers";
if (!user) error(404, "User not found");
Use it after a request-dependent check in a page() or partial(). The never return type tells TypeScript that execution does not continue after the call.
Bun Error Handling
MiniFW lets the error reach Bun's error server option. Use isMiniError() to narrow the caught value and return its intended status and message:
import { mini } from "@calvinbonner/minifw/core";
import { isMiniError } from "@calvinbonner/minifw/helpers";
mini({
error(caught) {
if (isMiniError(caught)) {
return new Response(caught.message, { status: caught.status });
}
console.error(caught);
return new Response("Internal Server Error", { status: 500 });
},
});
isMiniError() returns false for ordinary exceptions, which remain available to the same Bun error handler. Use redirectTo(), not error(), when the response should redirect rather than fail. See isMiniError() for the guard's full reference.