{"record":{"id":"80084512384a4fb6","repo":"ginuerzh/gost","slug":"returned-status-code-d","errorCode":null,"errorMessage":"returned status code %d","messagePattern":"returned status code (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resolver.go","lineNumber":913,"sourceCode":"\t}\n\n\t// req.Header.Add(\"Content-Type\", \"application/dns-udpwireformat\")\n\treq.Header.Add(\"Content-Type\", \"application/dns-message\")\n\treq.Host = ex.endpoint.Hostname()\n\n\tclient := ex.client\n\tif client == nil {\n\t\tclient = http.DefaultClient\n\t}\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to perform an HTTPS request: %s\", err)\n\t}\n\n\t// Check response status code\n\tdefer resp.Body.Close()\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"returned status code %d\", resp.StatusCode)\n\t}\n\n\t// Read wireformat response from the body\n\tbuf, err := io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to read the response body: %s\", err)\n\t}\n\n\treturn buf, nil\n}\n","sourceCodeStart":895,"sourceCodeEnd":924,"githubUrl":"https://github.com/ginuerzh/gost/blob/a33fdbf4c98034f4bfeeaea9868909822b9c526d/resolver.go#L895-L924","documentation":"The DoH server answered, but with a non-200 HTTP status (resolver.go:913). dohExchanger.Exchange only accepts http.StatusOK, since a DNS-over-HTTPS response must be 200 with an application/dns-message body per RFC 8484; any other code (4xx/5xx) means the query was not successfully processed.","triggerScenarios":"Exchange() on a dohExchanger where client.Do succeeded but the server returned 400 (malformed DNS query), 404/410 (wrong endpoint path), 429 (rate limiting), 401/403 (auth required), 500/502/503 (server error), or a proxy returning an error page.","commonSituations":"DoH endpoint URL pointing at the wrong path (e.g. missing /dns-query); server rate-limiting high query volume; reverse proxy/auth gateway in front of the resolver rejecting requests; DoH provider outage returning 5xx; sending queries the resolver refuses to process.","solutions":["Log/inspect resp.StatusCode (wrap it into the error at the call site) and match it against the DoH provider's documented codes","Verify the endpoint URL includes the correct path (usually https://provider/dns-query)","If 429: add backoff/retry with jitter or reduce query rate","If 401/403: supply required auth (token, mTLS via tlsConfig) for the resolver","If 5xx: retry later or switch to a backup DoH provider"],"exampleFix":"// before\nbuf, err := exchanger.Exchange(ctx, query)\n// err: returned status code 404 (wrong path in endpoint URL)\n// after\nendpoint, _ := url.Parse(\"https://dns.example.com/dns-query\") // correct RFC 8484 path\nexchanger := NewDoHExchanger(endpoint, nil)\nbuf, err := exchanger.Exchange(ctx, query)","handlingStrategy":"retry","validationCode":"u, err := url.Parse(dohURL)\nif err != nil || u.Path == \"\" || u.Path == \"/\" {\n    return fmt.Errorf(\"DoH endpoint likely missing /dns-query path: %q\", dohURL)\n}","typeGuard":"func isNon200Status(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"returned status code \")\n}\nfunc extractStatusCode(err error) (int, bool) {\n    if !isNon200Status(err) { return 0, false }\n    var code int\n    _, scanErr := fmt.Sscanf(err.Error(), \"returned status code %d\", &code)\n    return code, scanErr == nil\n}","tryCatchPattern":"buf, err := exchanger.Exchange(ctx, query)\nif err != nil {\n    if code, ok := extractStatusCode(err); ok {\n        switch {\n        case code == http.StatusTooManyRequests:\n            // back off and retry later\n        case code == http.StatusNotFound:\n            // fix endpoint path\n        case code >= 500:\n            // retry with backoff or fail over to another resolver\n        }\n    }\n    return err\n}","preventionTips":["Use the provider's documented RFC 8484 path (usually /dns-query)","Parse the endpoint with url.Parse and validate scheme+path before constructing the exchanger","Add retry with exponential backoff for 429/5xx responses","Supply auth/mTLS when the resolver requires it","Monitor provider status pages and configure a backup DoH resolver"],"tags":["network","dns","https","http-status","doh"],"backgroundTag":"http-non-200-status","analyzedSha":"a33fdbf4c98034f4bfeeaea9868909822b9c526d","analyzedAt":"2026-09-02T22:15:54.506Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}