agents
agents copied to clipboard
Add error handling for default get-messages request and message parsing
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 theonErrorcallback option if provided. - Adds the same error handling as the above in the places marked as TODO, to keep things consistent.