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:
@@ -7,15 +7,19 @@ export const rpcApp = new Hono();
|
|||||||
|
|
||||||
const handler = new RPCHandler(router);
|
const handler = new RPCHandler(router);
|
||||||
|
|
||||||
rpcApp.use("/*", async (c, next) => {
|
rpcApp.all("/*", async (c) => {
|
||||||
const { matched, response } = await handler.handle(c.req.raw, {
|
try {
|
||||||
prefix: "/rpc",
|
const { matched, response } = await handler.handle(c.req.raw, {
|
||||||
});
|
prefix: "/rpc",
|
||||||
|
});
|
||||||
|
|
||||||
if (matched) {
|
if (matched) {
|
||||||
return c.newResponse(response.body, response);
|
return c.newResponse(response.body, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.json({ error: "Not found" }, 404);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("RPC Handler error:", error);
|
||||||
|
return c.json({ error: "Internal server error" }, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
await next();
|
|
||||||
return;
|
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user