{"record":{"id":"ed4d75481bee8484","repo":"jeessy2/ddns-go","slug":"rainyun-api-error-code-d","errorCode":null,"errorMessage":"Rainyun API error, code=%d","messagePattern":"Rainyun API error, code=(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dns/rainyun.go","lineNumber":260,"sourceCode":"\tif method == http.MethodPost || method == http.MethodPatch || method == http.MethodPut {\n\t\treq.Header.Set(\"Content-Type\", \"application/json\")\n\t}\n\n\tresp, err := rainyun.httpClient.Do(req)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tvar apiResp RainyunResp\n\terr = util.GetHTTPResponse(resp, err, &apiResp)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif apiResp.Code != 200 {\n\t\tif apiResp.Message != \"\" {\n\t\t\treturn fmt.Errorf(\"%s\", apiResp.Message)\n\t\t}\n\t\treturn fmt.Errorf(\"Rainyun API error, code=%d\", apiResp.Code)\n\t}\n\n\tif result == nil {\n\t\treturn nil\n\t}\n\n\tdataBytes, err := json.Marshal(apiResp.Data)\n\tif err != nil {\n\t\treturn err\n\t}\n\treturn json.Unmarshal(dataBytes, result)\n}\n","sourceCodeStart":242,"sourceCodeEnd":273,"githubUrl":"https://github.com/jeessy2/ddns-go/blob/5874c2e6667c69357ab95079421131104bd3fcae/dns/rainyun.go#L242-L273","documentation":"dns/rainyun.go fallback error: when the Rainyun API returns code != 200 but the response Message field is empty, request() (used by getRecordList, createRecord, patchRecord) reports \"Rainyun API error, code=%d\" with the numeric code only. It exists so callers never get an empty error string.","triggerScenarios":"Any Rainyun API call whose JSON body has code != 200 and an empty Message — typically provider-side failures that omit a human-readable message (5xx-style conditions, unknown codes, malformed provider responses).","commonSituations":"Rainyun backend incidents returning error codes without messages; API version changes that alter the response envelope; proxy middleware stripping the JSON body.","solutions":["Look up the numeric code in the Rainyun API documentation","Retry if the code is in the 5xx range; it may be transient","Check Rainyun status page or console for ongoing incidents","Update the library/provider SDK if the API response format changed"],"exampleFix":"// before\nreturn fmt.Errorf(\"Rainyun API error, code=%d\", apiResp.Code)\n// after (caller: retry on transient codes)\nif strings.Contains(err.Error(), \"code=5\") {\n\ttime.Sleep(2 * time.Second)\n\treturn provider.getRecordList(domain) // retry once\n}","handlingStrategy":"retry","validationCode":"// preflight: ensure API reachable and key set\nif apiKey == \"\" { return errors.New(\"rainyun: missing API key\") }","typeGuard":"// detect the code-only fallback error\nfunc isCodeOnlyErr(err error) (code int, ok bool) {\n\t_, e := fmt.Sscanf(errString(err), \"Rainyun API error, code=%d\", &code)\n\treturn code, e == nil\n}","tryCatchPattern":"if err != nil {\n\tif code, ok := isCodeOnlyErr(err); ok && code >= 500 {\n\t\ttime.Sleep(2 * time.Second)\n\t\treturn retryOnce()\n\t}\n\treturn err\n}","preventionTips":["Retry only 5xx-style codes; fail fast on others","Watch the Rainyun status page for incidents","Keep the provider SDK/library updated for envelope changes"],"tags":["api-error","http-status","rainyun"],"backgroundTag":"http-non-2xx-api-response","analyzedSha":"5874c2e6667c69357ab95079421131104bd3fcae","analyzedAt":"2026-09-03T15:41:16.799Z","contentChangedAt":"2026-09-03T15:41:16.799Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}