{"record":{"id":"02aa881a58c59b62","repo":"Billionmail/BillionMail","slug":"base-url-accessibility-test-failed-w","errorCode":null,"errorMessage":"base URL accessibility test failed: %w","messagePattern":"base URL accessibility test failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/internal/service/askai/supplier.go","lineNumber":497,"sourceCode":"// 2. Tests the accessibility of the base URL by sending a HEAD request.\n// 3. Validates the API key by sending a GET request to the models endpoint.\n// If any of these checks fail, it returns an error indicating the issue.\nfunc Testing(supplierName, baseUrl, apiKey string) error {\n\tif supplierName == \"\" || baseUrl == \"\" || apiKey == \"\" {\n\t\treturn errors.New(\"supplier name, base URL, and API key are required\")\n\t}\n\n\t// Validate base URL format\n\tparsedUrl, err := url.ParseRequestURI(baseUrl)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"invalid base URL format: %w\", err)\n\t}\n\tif parsedUrl.Scheme != \"http\" && parsedUrl.Scheme != \"https\" {\n\t\treturn errors.New(\"base URL must use http or https protocol\")\n\t}\n\t// Ensure the base URL ends with a slash\n\tif err := testBaseURLAccessibility(baseUrl); err != nil {\n\t\treturn fmt.Errorf(\"base URL accessibility test failed: %w\", err)\n\t}\n\t// Validate API key by making a request to the models endpoint\n\tif err := testAPIKeyValidity(baseUrl, apiKey); err != nil {\n\t\treturn fmt.Errorf(\"API key validation failed: %w\", err)\n\t}\n\n\treturn nil\n}\n\n// testBaseURLAccessibility checks if the base URL is accessible by sending a HEAD request.\n// It returns an error if the request fails or if the response status is not OK (200).\nfunc testBaseURLAccessibility(baseUrl string) error {\n\tclient := &http.Client{Timeout: 3 * time.Second}\n\tresp, err := client.Head(baseUrl)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer resp.Body.Close()","sourceCodeStart":479,"sourceCodeEnd":515,"githubUrl":"https://github.com/Billionmail/BillionMail/blob/fc36c76c050c3775c5e899faf7403cf0262d2744/core/internal/service/askai/supplier.go#L479-L515","documentation":"Testing probes base URL reachability with a HEAD request via testBaseURLAccessibility. Any failure — DNS failure, connection refused, timeout, TLS error, or non-success status — is wrapped as 'base URL accessibility test failed: %w'. The wrapped cause contains the real network error.","triggerScenarios":"Calling askai.Testing against a host that is down, unreachable, behind a firewall, has expired TLS certificates, or returns an error HTTP status to HEAD requests.","commonSituations":"Typo'd hostname or wrong port; server running locally but Testing called in an environment without access (Docker network mismatch); corporate proxy blocking the request; self-signed/expired certs; endpoint only supports GET, not HEAD.","solutions":["Inspect the wrapped inner error to identify the exact network cause (DNS, refused, timeout, TLS)","Confirm the URL is reachable: curl -I <baseUrl> from the same host/network","Check DNS, firewall, and proxy settings; for containers verify network reachability","Verify the server accepts HEAD requests or correct the endpoint URL","Fix TLS certificate issues or use http:// for local-only endpoints"],"exampleFix":"// before\nerr := askai.Testing(name, \"http://localhost:9999/v1\", key) // server not running\n// after\n// start the service first, or use the correct port\nif err := exec.Command(\"curl\", \"-sfI\", baseURL); err != nil { /* fix reachability */ }\nerr := askai.Testing(name, \"http://localhost:8080/v1\", key)","handlingStrategy":"retry","validationCode":"func baseURLReachable(raw string) error {\n    ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)\n    defer cancel()\n    req, err := http.NewRequestWithContext(ctx, http.MethodHead, raw, nil)\n    if err != nil { return err }\n    resp, err := http.DefaultClient.Do(req)\n    if err != nil { return err }\n    resp.Body.Close()\n    return nil\n}\n// call before askai.Testing to fail fast with a clearer error","typeGuard":null,"tryCatchPattern":"var err error\nfor attempt := 0; attempt < 3; attempt++ {\n    err = askai.Testing(name, baseUrl, apiKey)\n    if err == nil || !strings.Contains(err.Error(), \"accessibility test failed\") { break }\n    time.Sleep(time.Duration(1<<attempt) * time.Second)\n}\nif err != nil { return fmt.Errorf(\"supplier endpoint unreachable: %w\", err) }","preventionTips":["Verify the endpoint with curl -I from the same host/network before testing","Check DNS, firewall, and proxy configuration in the deployment environment","Confirm the service is running and the port is correct (esp. in Docker networks)","Keep reasonable timeouts and retry transient network failures"],"tags":["go","network","http","supplier","connectivity"],"backgroundTag":"base-url-unreachable","analyzedSha":"fc36c76c050c3775c5e899faf7403cf0262d2744","analyzedAt":"2026-09-05T21:28:54.019Z","contentChangedAt":"2026-09-05T21:28:54.019Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}