linshenkx/prompt-optimizer · warning · Error

customHeaderError

Error message

customHeaderError

What it means

saveForm runs getCustomHeaderValidationMessage() and rethrows its message when custom HTTP headers on the form are malformed. This is not a fixed message: the thrown text is the validation message produced for the invalid header entry (duplicate names, empty keys, invalid characters, or bad JSON where applicable).

Source

Thrown at packages/ui/src/composables/model/useTextModelManager.ts:905

      modelMeta,
      connectionConfig,
      paramOverrides: { ...(form.value.paramOverrides ?? {}) }
    } as TextModelConfig

    await modelManager.addModel(modelKey, newConfig)
    return modelKey
  }

  const saveForm = async () => {
    if (isSaving.value) return null
    if (!canSaveForm.value) {
      throw new Error('No provider or model selected')
    }
    isSaving.value = true
    try {
      const customHeaderError = getCustomHeaderValidationMessage()
      if (customHeaderError) {
        throw new Error(customHeaderError)
      }

      const savedId = editingModelId.value ? await updateExistingModel() : await createNewModel()
      await loadModels()
      return savedId
    } finally {
      isSaving.value = false
    }
  }

  const testFormConnection = async () => {
    // 使用 canTestFormConnection 的完整校验逻辑
    if (!canTestFormConnection.value) return

    isTestingFormConnection.value = true
    formConnectionStatus.value = { type: 'info', message: t('modelManager.testing') }

    try {

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Fix or remove the offending custom header row (fill both name and value, remove duplicates/empties)
  2. Trim header names/values before validation
  3. If headers are unused, clear the custom headers list entirely
  4. Add row-level validation in the UI so the user sees which row is invalid

Example fix

// before
Authorization: 
Authorization: Bearer x

// after
Authorization: Bearer x
Defensive patterns

Strategy: validation

Validate before calling

const headers = form.value.customHeaders.filter((h) => h.name.trim() && h.value.trim())
const names = headers.map((h) => h.name.trim().toLowerCase())
if (new Set(names).size !== names.length) { /* duplicate header; fix before save */ }

Type guard

const isValidHeader = (h: { name?: string; value?: string }): h is { name: string; value: string } =>
  typeof h.name === 'string' && h.name.trim().length > 0 && typeof h.value === 'string' && h.value.trim().length > 0

Try / catch

try { await saveForm() } catch (e) { if (String(e?.message) !== 'No provider or model selected' && /header/i.test(String(e?.message))) { highlightHeaderRow() } else throw e }

Prevention

When it happens

Trigger: Adding custom headers in the model form with an empty header name, a name/value containing invalid characters, whitespace-only entries, or duplicate header names. Any non-empty return from the validator triggers the throw before save.

Common situations: Pasting a header row with trailing newline creating an empty entry; duplicating an existing header; copy-pasting 'Authorization' twice; leaving a header row half-filled after adding a row in the UI.

Related errors


AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27). Data as JSON: /api/errors/32bbd8b6dc3b8a43. Report an issue: GitHub.