hasura/graphql-engine · error

failed parsing json: %w; response from API: %s

Error message

failed parsing json: %w; response from API: %s

What it means

NewHasuraError tries to unmarshal a non-2xx response body into HasuraError JSON; if the body is not valid JSON it wraps the parse failure plus the raw response text so nothing is hidden.

Source

Thrown at cli/migrate/database/hasuradb/types.go:189

		return ""
	}

	return strings.Join(errorStrings, "\r\n")
}

// NewHasuraError - returns error based on data and isCmd.
func NewHasuraError(data []byte, isCmd bool) error {
	var op errors.Op = "hasuradb.NewHasuraError"

	switch isCmd {
	case true:
		var herror HasuraError

		err := json.Unmarshal(data, &herror)
		if err != nil {
			return errors.E(
				op,
				fmt.Errorf("failed parsing json: %w; response from API: %s", err, string(data)),
			)
		}

		return herror
	default:
		return errors.E(op, fmt.Errorf("data error: %s", string(data)))
	}
}

View on GitHub (pinned to 724551b9ae)

Solutions

  1. Check the response snippet in the message to identify what actually answered (proxy? login page?)
  2. Verify the HASURA_GRAPHQL_ENDPOINT URL points directly at the Hasura server
  3. Fix proxy configuration or admin secret so real Hasura JSON errors are returned
Defensive patterns

Strategy: try-catch

Validate before calling

resp, err := http.Get(endpoint + "/healthz")
if err != nil || resp.StatusCode != 200 {
    return fmt.Errorf("endpoint %s is not a healthy Hasura server", endpoint)
}

Try / catch

// inspect message for raw body; if it contains '<html' the answer came from a proxy, not Hasura
if err != nil && strings.Contains(err.Error(), "<html") {
    // fix endpoint/proxy/admin secret instead of retrying
}

Prevention

When it happens

Trigger: Any hasuradb API call that returns an error response whose body is HTML (proxy error page, auth portal) or plain text instead of the expected Hasura error JSON.

Common situations: Hasura behind a reverse proxy returning 502/503 HTML pages, wrong endpoint pointing at a non-Hasura service, gateways requiring authentication, or a very old server without JSON error responses.

Related errors


AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28). Data as JSON: /api/errors/03de8671de406eb7. Report an issue: GitHub.