gofr-dev/gofr · error

error parsing response

Error message

error parsing response

What it means

Same errClaimPathNotFound family as the mid-path case: during nested traversal the next key does not exist in the current map (next == false after map lookup), so the library returns the error with the fully traversed prefix. Reached whenever a map exists at the current level but lacks the requested segment.

Source

Thrown at pkg/gofr/datasource/elasticsearch/elasticsearch.go:32

	"go.opentelemetry.io/otel/attribute"
	"go.opentelemetry.io/otel/trace"
)

const (
	statusDown     = "DOWN"
	statusUp       = "UP"
	defaultTimeout = 5 * time.Second
)

var (
	errEmptyIndex        = errors.New("index name cannot be empty")
	errEmptyDocumentID   = errors.New("document ID cannot be empty")
	errEmptyQuery        = errors.New("query cannot be empty")
	errEmptyOperations   = errors.New("operations cannot be empty")
	errHealthCheckFailed = errors.New("elasticsearch health check failed")
	errOperation         = errors.New("elasticsearch operation error")
	errMarshaling        = errors.New("error marshaling data")
	errParsingResponse   = errors.New("error parsing response")
	errResponse          = errors.New("invalid elasticsearch response")
	errEncodingOperation = errors.New("error encoding operation")
)

// Config holds the configuration for connecting to Elasticsearch.
type Config struct {
	Addresses []string
	Username  string
	Password  string
}

// Client represents the Elasticsearch client.
type Client struct {
	config  Config
	client  *es.Client
	logger  Logger
	metrics Metrics
	tracer  trace.Tracer

View on GitHub (pinned to 187eb24962)

Solutions

  1. Verify against an actual decoded token and fix the final segment of the path
  2. Configure the issuer to always include the leaf key in the nested object
  3. Catch with errors.Is(err, errClaimPathNotFound) and map to a 401 with a descriptive message including the failing prefix

Example fix

// before
extractClaimValue(claims, "realm_access.rols") // typo
// after
extractClaimValue(claims, "realm_access.roles")
Defensive patterns

Strategy: try-catch

Validate before calling

perms, ok := claims["permissions"].(map[string]any)
if !ok { return fmt.Errorf("permissions missing or not an object") }
if _, ok := perms["role"]; !ok {
    return fmt.Errorf("permissions.role missing from token")
}

Type guard

func hasLeaf(claims jwt.MapClaims, parent, leaf string) bool {
    m, ok := claims[parent].(map[string]any)
    if !ok { return false }
    _, ok = m[leaf]
    return ok
}

Try / catch

v, err := extractClaimValue(claims, "permissions.role")
if errors.Is(err, errClaimPathNotFound) {
    // deny by default (403) and record the missing leaf path
}

Prevention

When it happens

Trigger: Path "permissions.role" where claims["permissions"] is a map but has no "role" key; missing deeper keys like "realm_access.roles" when realm_access exists but roles was dropped.

Common situations: User tokens without the specific role entry; IdP per-client claim filters that exclude the key; expecting a claim that only premium/specific-audience tokens contain.

Related errors


AI-assisted analysis of gofr-dev/gofr@187eb24962 (2026-09-01). Data as JSON: /api/errors/d5892eee0107f2a0. Report an issue: GitHub.