jeessy2/ddns-go · error

dnsla 请求失败,状态码: %d, 响应: %s

Error message

dnsla 请求失败,状态码: %d, 响应: %s

What it means

If the dnsla API responds but with a non-200 status, request() returns this error embedding the status code and the raw response body. It means dnsla received and answered the request but rejected it — an application-level API error (auth, rate limit, bad parameters), not a transport failure.

Source

Thrown at dns/dnsla.go:239

	// 设置自定义 Headers
	byteBuff := []byte(dnsla.DNS.ID + ":" + dnsla.DNS.Secret)
	token := "Basic " + base64.StdEncoding.EncodeToString(byteBuff)
	req.Header.Set("Authorization", token)
	req.Header.Set("Content-Type", "application/json;charset=utf-8")
	// 4. 发送请求
	client := dnsla.httpClient
	resp, err := client.Do(req)
	if err != nil {
		return nil, fmt.Errorf("请求 dnsla 失败: %w", err)
	}
	defer resp.Body.Close()

	body, err = io.ReadAll(resp.Body)
	if err != nil {
		return nil, fmt.Errorf("读取 dnsla 响应失败: %w", err)
	}
	if resp.StatusCode != http.StatusOK {
		return nil, fmt.Errorf("dnsla 请求失败,状态码: %d, 响应: %s", resp.StatusCode, string(body))
	}
	return body, nil
}

// 获得域名记录列表
func (dnsla *Dnsla) getRecordList(domain *config.Domain, typ string) (result []byte, err error) {
	recordTypeInt := "1"
	if typ == "AAAA" {
		recordTypeInt = "28"
	}
	params := domain.GetCustomParams()
	params.Set("domain", domain.DomainName)
	params.Set("host", domain.GetSubDomain())
	params.Set("type", recordTypeInt)
	params.Set("pageIndex", "1")
	params.Set("pageSize", "999")

	url := recordList + "?" + params.Encode()

View on GitHub (pinned to 5874c2e666)

Solutions

  1. Read the 响应 body in the error — dnsla usually explains the rejection (auth error, param error)
  2. Verify dnsla.DNS.ID and DNS.Secret are correct and not expired; regenerate credentials if needed
  3. Handle 429 by backing off and retrying; check the API rate-limit docs
  4. Validate record parameters (domain, type, value, TTL) against the dnsla API spec for 4xx errors
  5. For 5xx, treat as server-side: retry later and check dnsla service status

Example fix

// before
if resp.StatusCode != http.StatusOK {
  return nil, fmt.Errorf("dnsla 请求失败,状态码: %d, 响应: %s", resp.StatusCode, string(body))
}
// after
if resp.StatusCode != http.StatusOK {
  if resp.StatusCode == http.StatusTooManyRequests {
    time.Sleep(retryAfter) // honor Retry-After header
    return dnsla.request(method, apiAddr, values)
  }
  return nil, fmt.Errorf("dnsla 请求失败,状态码: %d, 响应: %s", resp.StatusCode, string(body))
}
Defensive patterns

Strategy: fallback

Validate before calling

// verify credentials are set and non-empty before calling the API
if dnsla.DNS.ID == "" || dnsla.DNS.Secret == "" {
  return errors.New("dnsla 凭证未配置")
}

Type guard

null

Try / catch

if resp.StatusCode != http.StatusOK {
  switch {
  case resp.StatusCode == http.StatusUnauthorized:
    return nil, errors.New("dnsla 认证失败,请检查 ID/Secret")
  case resp.StatusCode == http.StatusTooManyRequests:
    return nil, retryLater(fmt.Errorf("dnsla 限流: %s", string(body)))
  default:
    return nil, fmt.Errorf("dnsla 请求失败,状态码: %d, 响应: %s", resp.StatusCode, string(body))
  }
}

Prevention

When it happens

Trigger: create/modify -> request gets a response with StatusCode != http.StatusOK: invalid/expired Basic-auth credentials (DNS.ID/DNS.Secret), rate limiting (429), invalid record parameters (400/422), or server-side 5xx.

Common situations: Wrong or rotated dnsla API ID/Secret; exceeding API rate limits; malformed record data the API rejects; dnsla service outage returning 5xx; account permission issues.

Related errors


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