agents icon indicating copy to clipboard operation
agents copied to clipboard

Add error handling for default get-messages request and message parsing

Open nickfujita opened this issue 6 months ago • 1 comments

Fixes issue where app crashes upon receiving a 40x response from default request to /get-messages. Came across this while testing authentication with the agent, using the method prescribed in hono-agents

// or with authentication
app.use(
  "*",
  agentsMiddleware({
    options: {
      // onBeforeConnect: async (req) => { // original
      onBeforeRequest: async (req) => { // modified
        const token = req.headers.get("authorization");
        // validate token
        if (!token) return new Response("Unauthorized", { status: 401 });
      },
    },
  })
);
  • Adds error handling to default request to /get-messages, setting the error message on the hook return object, and calling the onError callback option if provided.
  • Adds the same error handling as the above in the places marked as TODO, to keep things consistent.

nickfujita avatar Apr 16 '25 07:04 nickfujita