{"record":{"id":"4cf30353670d690b","repo":"fish2018/pansou","slug":"s-d-4cf303","errorCode":null,"errorMessage":"[%s] 会话返回状态码: %d","messagePattern":"\\[(.+?)\\] 会话返回状态码: (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/nsgame/nsgame.go","lineNumber":370,"sourceCode":"\tif body != nil {\n\t\treader = strings.NewReader(string(body))\n\t}\n\treq, err := http.NewRequestWithContext(ctx, http.MethodPost, baseURL+path, reader)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] 创建会话请求失败: %w\", p.Name(), err)\n\t}\n\tif body != nil {\n\t\treq.Header.Set(\"Content-Type\", \"application/json\")\n\t}\n\tp.setRequestHeaders(req, \"https://nsthwj.cn/\")\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"[%s] 会话请求失败: %w\", p.Name(), err)\n\t}\n\tdefer resp.Body.Close()\n\tdata, _ := io.ReadAll(resp.Body)\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"[%s] 会话返回状态码: %d\", p.Name(), resp.StatusCode)\n\t}\n\treturn data, nil\n}\n\nfunc solveChallenge(challenge string, difficultyBits int) string {\n\tfor nonce := int64(0); nonce < 10000000; nonce++ {\n\t\tsum := sha256.Sum256([]byte(fmt.Sprintf(\"%s:%d\", challenge, nonce)))\n\t\tfullBytes, remainder := difficultyBits/8, difficultyBits%8\n\t\tvalid := true\n\t\tfor i := 0; i < fullBytes; i++ {\n\t\t\tif sum[i] != 0 {\n\t\t\t\tvalid = false\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tif valid && remainder > 0 && sum[fullBytes]>>(8-remainder) != 0 {\n\t\t\tvalid = false\n\t\t}","sourceCodeStart":352,"sourceCodeEnd":388,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/nsgame/nsgame.go#L352-L388","documentation":"postSessionRaw treats any non-200 HTTP status from the session endpoints as a hard failure and returns this error containing the numeric status code. Unlike the transport error, an actual HTTP response was received but the server rejected the session establishment (challenge fetch or issue call).","triggerScenarios":"After client.Do succeeds, resp.StatusCode != http.StatusOK when POSTing to /traffic/session/challenge or /traffic/session/issue. Note the error is returned before reading the body, so the response body (which may contain the actual server error reason) is discarded.","commonSituations":"Site returns 403/429 due to anti-bot protection (the plugin does solve a PoW challenge, but the site may still block), 5xx during server maintenance, or a Cloudflare challenge page replacing the API response.","solutions":["Log the response body (currently read into data but not included in the error) to see the server's actual rejection reason.","Check for rate limiting (429) and add delays/backoff between session attempts.","If 403, inspect whether required cookies/headers (set by p.setRequestHeaders) match what the site currently expects.","Retry after a delay for 5xx; the site may be under maintenance.","Verify the site API hasn't changed (check in browser devtools) if you consistently get 404/410."],"exampleFix":"// before\nif resp.StatusCode != http.StatusOK {\n    return nil, fmt.Errorf(\"[%s] 会话返回状态码: %d\", p.Name(), resp.StatusCode)\n}\n// after\nif resp.StatusCode != http.StatusOK {\n    return nil, fmt.Errorf(\"[%s] 会话返回状态码: %d, body: %s\", p.Name(), resp.StatusCode, string(data))\n}","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"data, err := p.postSessionRaw(client, path, body)\nif err != nil {\n    var httpErr *HTTPStatusError // if you extend the plugin to use one\n    if errors.As(err, &httpErr) && httpErr.Code == http.StatusTooManyRequests {\n        time.Sleep(backoff)\n        // retry\n    }\n}","preventionTips":["Include the response body in the error so the server's rejection reason is visible.","Throttle request rate to avoid 429/403 anti-bot responses.","Keep request headers (UA, cookies) current with what the site expects.","Treat 5xx as retryable and 4xx as non-retryable config/anti-bot issues."],"tags":["http","status-code","go","plugin"],"backgroundTag":"http-error-response","analyzedSha":"beaa56133755a548ebc51b090b3816e2ae044aa6","analyzedAt":"2026-09-07T00:31:18.025Z","contentChangedAt":"2026-09-07T00:31:18.025Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}