handle errors correctly in the other tools

This commit is contained in:
Kujtim Hoxha 2025-04-14 11:24:36 +02:00
parent 921f5ee5bd
commit 0b3e5f5bd4
8 changed files with 72 additions and 26 deletions

View file

@ -86,6 +86,7 @@ func (t *fetchTool) Info() ToolInfo {
"format": map[string]any{
"type": "string",
"description": "The format to return the content in (text, markdown, or html)",
"enum": []string{"text", "markdown", "html"},
},
"timeout": map[string]any{
"type": "number",
@ -126,7 +127,7 @@ func (t *fetchTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error
)
if !p {
return NewTextErrorResponse("Permission denied to fetch from URL: " + params.URL), nil
return ToolResponse{}, permission.ErrorPermissionDenied
}
client := t.client
@ -142,14 +143,14 @@ func (t *fetchTool) Run(ctx context.Context, call ToolCall) (ToolResponse, error
req, err := http.NewRequestWithContext(ctx, "GET", params.URL, nil)
if err != nil {
return NewTextErrorResponse("Failed to create request: " + err.Error()), nil
return ToolResponse{}, fmt.Errorf("failed to create request: %w", err)
}
req.Header.Set("User-Agent", "termai/1.0")
resp, err := client.Do(req)
if err != nil {
return NewTextErrorResponse("Failed to execute request: " + err.Error()), nil
return ToolResponse{}, fmt.Errorf("failed to fetch URL: %w", err)
}
defer resp.Body.Close()