flipped-aurora/gin-vue-admin · error
http_header 必须是 JSON 对象: %w
Error message
http_header 必须是 JSON 对象: %w
What it means
If t.HttpHeader is non-empty, runHTTP expects it to be a JSON object mapping header names to string values (map[string]string) and unmarshals it. Anything else — arrays, scalars, invalid JSON, nested objects — fails with this wrapped error.
Source
Thrown at server/service/system/sys_timed_task_runner.go:149
if u.Scheme != "http" && u.Scheme != "https" {
return "", fmt.Errorf("仅允许 http/https, 实际为 %q", u.Scheme)
}
method := strings.ToUpper(strings.TrimSpace(t.HttpMethod))
if method == "" {
method = http.MethodGet
}
var body io.Reader
if t.HttpBody != "" {
body = strings.NewReader(t.HttpBody)
}
req, err := http.NewRequest(method, t.HttpUrl, body)
if err != nil {
return "", fmt.Errorf("构造请求失败: %w", err)
}
if len(t.HttpHeader) > 0 {
var hdr map[string]string
if err := json.Unmarshal(t.HttpHeader, &hdr); err != nil {
return "", fmt.Errorf("http_header 必须是 JSON 对象: %w", err)
}
for k, v := range hdr {
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))View on GitHub (pinned to 3136500ef3)
Solutions
- Fix http_header to a valid JSON object with string values, e.g. {"Authorization":"Bearer x","X-Trace":"1"}
- Convert non-string values to strings before saving
- Validate the JSON shape in the frontend form before submitting
Example fix
// before
HttpHeader: '["Authorization: Bearer abc"]'
// after
HttpHeader: '{"Authorization":"Bearer abc"}' Defensive patterns
Strategy: validation
Validate before calling
if httpHeader != "" {
var hdr map[string]string
if err := json.Unmarshal([]byte(httpHeader), &hdr); err != nil {
return fmt.Errorf("http_header must be a JSON object of string values: %w", err)
}
} Type guard
func isValidHeaderJSON(s string) bool {
if s == "" { return true }
var hdr map[string]string
return json.Unmarshal([]byte(s), &hdr) == nil
} Try / catch
if err := RunTask(t); err != nil {
if strings.Contains(err.Error(), "http_header 必须是 JSON 对象") {
log.Warnf("task %d has invalid http_header JSON", t.ID)
}
} Prevention
- Provide a key/value pair editor in the UI that serializes to JSON, instead of a raw textarea
- Validate the JSON shape on save (object of string->string only)
- Keep header values as strings; stringify numbers/booleans before saving
When it happens
Trigger: t.HttpHeader contains invalid JSON, a JSON array like ["a: b"], a number/string, or nested object values where strings are required.
Common situations: Admin pasted raw 'Authorization: Bearer x' text instead of a JSON object; JSON with non-string values like {"timeout": 30}; export/import corrupted the column.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- LLM request failed
- params 必须是合法 JSON
- httpUrl 必须是合法的 http/https 地址
- httpHeader 必须是 {"Key":"Value"} 形式的 JSON 对象
- parse duration < 0
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/f581416c51a2bbab.
Report an issue: GitHub.