flipped-aurora/gin-vue-admin · error

非 2xx 响应: %d

Error message

非 2xx 响应: %d

What it means

runHTTP treats any response status outside 200-299 as a failed call. It still returns the output string ('HTTP <code>: <body>', body capped at maxHTTPRespBytes) but the error is 非 2xx 响应: <code>. This makes the timed task's status reflect endpoint-level failure, not just transport errors.

Source

Thrown at server/service/system/sys_timed_task_runner.go:170

			req.Header.Set(k, v)
		}
	}

	client := newTimedTaskHTTPClient(t.HttpAllowPrivate, defaultHTTPTimeout)
	resp, err := client.Do(req)
	if err != nil {
		var uerr *url.Error
		if errors.As(err, &uerr) && uerr.Timeout() {
			return "", errTaskTimeout
		}
		return "", err
	}
	defer resp.Body.Close()

	data, _ := io.ReadAll(io.LimitReader(resp.Body, maxHTTPRespBytes))
	out := fmt.Sprintf("HTTP %d: %s", resp.StatusCode, string(data))
	if resp.StatusCode < 200 || resp.StatusCode >= 300 {
		return out, fmt.Errorf("非 2xx 响应: %d", resp.StatusCode)
	}
	return out, nil
}

// alertFailure 失败告警: 查 888 角色用户, 经本体 SSE Hub 定向推送(离线静默丢弃, 不阻塞)
func (s *TimedTaskService) alertFailure(t system.SysTimedTask, errMsg string) {
	var ids []uint
	if err := global.GVA_DB.Model(&system.SysUserAuthority{}).
		Where("sys_authority_authority_id = ?", alertAuthorityID).
		Pluck("sys_user_id", &ids).Error; err != nil {
		logger.Bg().Mod("timedTask").Err(err).Error("查询告警接收人失败")
		return
	}
	if len(ids) == 0 {
		return
	}
	payload, _ := json.Marshal(map[string]interface{}{
		"taskId": t.ID,

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Check the recorded output for the status code and response body to see the remote error
  2. Fix authentication/headers or payload so the endpoint returns 2xx
  3. Verify the callback endpoint URL is still correct after refactors
  4. If the endpoint is intermittently failing, fix or add retry handling at the target service

Example fix

// before
headers = {}
// after (target expects auth)
HttpHeader: '{"Authorization":"Bearer <token>"}'
Defensive patterns

Strategy: retry

Validate before calling

// pre-check endpoint reachability before scheduling the task
resp, err := http.Head(callbackURL)
if err != nil || resp.StatusCode >= 400 {
    log.Warn("callback endpoint unhealthy before scheduling")
}

Try / catch

out, err := RunTask(t)
if err != nil && strings.Contains(err.Error(), "非 2xx 响应") {
    log.Errorf("callback %s returned failure. output: %s", t.HttpUrl, out)
    // inspect status code and body in out to fix auth/payload
}

Prevention

When it happens

Trigger: The callback endpoint returned 4xx/5xx (400 bad payload, 401 auth failure, 404 wrong path, 500 server error).

Common situations: Callback URL expects an auth header that the http_header JSON no longer supplies; endpoint path changed after a deploy; target service temporarily down returning 502/503; payload rejected with 422.

Related errors


AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31). Data as JSON: /api/errors/5d49f642e89bf429. Report an issue: GitHub.