Fix: Improve RPC error handling and routing

- Changed from rpcApp.use to rpcApp.all for better route handling
- Added proper error handling with try-catch
- Return 404 for unmatched routes instead of calling next()
- Return 500 for internal server errors
- Improves RPC endpoint reliability and debugging
This commit is contained in:
2025-10-02 01:09:46 +02:00
parent 9a104e8862
commit c0b0edc00e

View File

@@ -7,7 +7,8 @@ export const rpcApp = new Hono();
const handler = new RPCHandler(router);
rpcApp.use("/*", async (c, next) => {
rpcApp.all("/*", async (c) => {
try {
const { matched, response } = await handler.handle(c.req.raw, {
prefix: "/rpc",
});
@@ -16,6 +17,9 @@ rpcApp.use("/*", async (c, next) => {
return c.newResponse(response.body, response);
}
await next();
return;
return c.json({ error: "Not found" }, 404);
} catch (error) {
console.error("RPC Handler error:", error);
return c.json({ error: "Internal server error" }, 500);
}
});