jeessy2/ddns-go · error

%s

Error message

%s

What it means

dns/rainyun.go request() checks the Rainyun API response code and, when it is not 200 and the payload carries a non-empty Message, returns that message verbatim via fmt.Errorf("%s", ...). It is a pass-through of the provider's own business-error text for getRecordList, createRecord, and patchRecord.

Source

Thrown at dns/rainyun.go:258

	// 认证
	req.Header.Set("x-api-key", rainyun.DNS.Secret)
	if method == http.MethodPost || method == http.MethodPatch || method == http.MethodPut {
		req.Header.Set("Content-Type", "application/json")
	}

	resp, err := rainyun.httpClient.Do(req)
	if err != nil {
		return err
	}

	var apiResp RainyunResp
	err = util.GetHTTPResponse(resp, err, &apiResp)
	if err != nil {
		return err
	}
	if apiResp.Code != 200 {
		if apiResp.Message != "" {
			return fmt.Errorf("%s", apiResp.Message)
		}
		return fmt.Errorf("Rainyun API error, code=%d", apiResp.Code)
	}

	if result == nil {
		return nil
	}

	dataBytes, err := json.Marshal(apiResp.Data)
	if err != nil {
		return err
	}
	return json.Unmarshal(dataBytes, result)
}

View on GitHub (pinned to 5874c2e666)

Solutions

  1. Read the returned message text — it is the provider's own explanation
  2. Verify the Rainyun API key (X-API-KEY) in your configuration
  3. Confirm the domain and subdomain exist in your Rainyun account
  4. Re-fetch the record list before patching to ensure record IDs are current

Example fix

// before
err := provider.patchRecord(domain, ip)
// after
if err != nil && strings.Contains(err.Error(), "api key") {
	log.Fatal("Rainyun API key invalid — update config")
} else if err != nil {
	log.Printf("Rainyun rejected request: %v", err)
}
Defensive patterns

Strategy: validation

Validate before calling

// verify domain/subdomain and key before calling
if apiKey == "" { return errors.New("rainyun: missing X-API-KEY") }
if domain.DomainName == "" || domain.SubDomain == "" {
	return errors.New("rainyun: domain and subdomain required")
}

Try / catch

if err != nil {
	// err.Message is the provider text — surface it to the user verbatim
	log.Printf("rainyun API rejected request: %v", err)
	return err
}

Prevention

When it happens

Trigger: Any Rainyun API call (getRecordList, createRecord, patchRecord) where the HTTP request succeeded but the JSON body has code != 200 and a non-empty Message field, e.g. invalid API key, record not found, or invalid parameters.

Common situations: Wrong or revoked Rainyun API key in config; subdomain not present under the configured domain; record ID stale after someone deleted the record in the Rainyun console; provider-side validation rejections.

Related errors


AI-assisted analysis of jeessy2/ddns-go@5874c2e666 (2026-09-03). Data as JSON: /api/errors/f4b569a8ed3df2e3. Report an issue: GitHub.