{"record":{"id":"f581416c51a2bbab","repo":"flipped-aurora/gin-vue-admin","slug":"http-header-json-w","errorCode":null,"errorMessage":"http_header 必须是 JSON 对象: %w","messagePattern":"http_header 必须是 JSON 对象: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/service/system/sys_timed_task_runner.go","lineNumber":149,"sourceCode":"\tif u.Scheme != \"http\" && u.Scheme != \"https\" {\n\t\treturn \"\", fmt.Errorf(\"仅允许 http/https, 实际为 %q\", u.Scheme)\n\t}\n\tmethod := strings.ToUpper(strings.TrimSpace(t.HttpMethod))\n\tif method == \"\" {\n\t\tmethod = http.MethodGet\n\t}\n\tvar body io.Reader\n\tif t.HttpBody != \"\" {\n\t\tbody = strings.NewReader(t.HttpBody)\n\t}\n\treq, err := http.NewRequest(method, t.HttpUrl, body)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"构造请求失败: %w\", err)\n\t}\n\tif len(t.HttpHeader) > 0 {\n\t\tvar hdr map[string]string\n\t\tif err := json.Unmarshal(t.HttpHeader, &hdr); err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"http_header 必须是 JSON 对象: %w\", err)\n\t\t}\n\t\tfor k, v := range hdr {\n\t\t\treq.Header.Set(k, v)\n\t\t}\n\t}\n\n\tclient := newTimedTaskHTTPClient(t.HttpAllowPrivate, defaultHTTPTimeout)\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\tvar uerr *url.Error\n\t\tif errors.As(err, &uerr) && uerr.Timeout() {\n\t\t\treturn \"\", errTaskTimeout\n\t\t}\n\t\treturn \"\", err\n\t}\n\tdefer resp.Body.Close()\n\n\tdata, _ := io.ReadAll(io.LimitReader(resp.Body, maxHTTPRespBytes))","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/service/system/sys_timed_task_runner.go#L131-L167","documentation":"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.","triggerScenarios":"t.HttpHeader contains invalid JSON, a JSON array like [\"a: b\"], a number/string, or nested object values where strings are required.","commonSituations":"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.","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"],"exampleFix":"// before\nHttpHeader: '[\"Authorization: Bearer abc\"]'\n// after\nHttpHeader: '{\"Authorization\":\"Bearer abc\"}'","handlingStrategy":"validation","validationCode":"if httpHeader != \"\" {\n    var hdr map[string]string\n    if err := json.Unmarshal([]byte(httpHeader), &hdr); err != nil {\n        return fmt.Errorf(\"http_header must be a JSON object of string values: %w\", err)\n    }\n}","typeGuard":"func isValidHeaderJSON(s string) bool {\n    if s == \"\" { return true }\n    var hdr map[string]string\n    return json.Unmarshal([]byte(s), &hdr) == nil\n}","tryCatchPattern":"if err := RunTask(t); err != nil {\n    if strings.Contains(err.Error(), \"http_header 必须是 JSON 对象\") {\n        log.Warnf(\"task %d has invalid http_header JSON\", t.ID)\n    }\n}","preventionTips":["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"],"tags":["json","validation","http","timed-task"],"backgroundTag":"schema-validation-failed","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}