Error Handling
Define custom error handlers to handle all errors in your app.
Usage
typescript
const app = new Kyrin({
onError: (err, c) => {
console.error(err);
return c.json({ error: err.message }, 500);
}
});Validation Errors
Works with Zod validation:
typescript
import { z } from "zod";
const app = new Kyrin({
onError: (err, c) => {
if (err.name === "ZodError") {
return c.json({
error: "Validation failed",
issues: err.issues
}, 400);
}
return c.json({ error: err.message }, 500);
}
});
const userSchema = z.object({ name: z.string() });
app.post("/users", userSchema, (c) => {
const body = c.body();
return c.json(body);
});Default Behavior
If you don't define onError:
- Development mode: Shows error details with stack trace
- Production mode: Shows "Internal Server Error" only