chore: improve error handling and config file creation in main.go

Amolith created

Improve error handling in handleCreateTask function by logging the API response
body when an error occurs. Update the success message to include the task ID.
Modify the createDefaultConfigFile function to use os.OpenFile instead of
os.Create for better file handling.

Change summary

main.go | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

Detailed changes

main.go 🔗

@@ -331,6 +331,7 @@ func handleCreateTask(
 
 	if resp.StatusCode < 200 || resp.StatusCode >= 300 {
 		respBody, _ := io.ReadAll(resp.Body)
+		log.Printf("Lunatask API error (status %d): %s", resp.StatusCode, string(respBody))
 		return &mcp.CallToolResult{
 			IsError: true,
 			Content: []mcp.Content{mcp.TextContent{Type: "text", Text: fmt.Sprintf("API error (status %d): %s", resp.StatusCode, string(respBody))}},
@@ -353,7 +354,7 @@ func handleCreateTask(
 		Content: []mcp.Content{
 			mcp.TextContent{
 				Type: "text",
-				Text: fmt.Sprint("Task created successfully.", response.Task.ID),
+				Text: fmt.Sprintf("Task created successfully with ID: %s", response.Task.ID),
 			},
 		},
 	}, nil
@@ -375,7 +376,7 @@ func createDefaultConfigFile(configPath string) {
 			}},
 		}},
 	}
-	file, err := os.Create(configPath)
+	file, err := os.OpenFile(configPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o600)
 	if err != nil {
 		log.Fatalf("Failed to create default config at %s: %v", configPath, err)
 	}