context = $context; } /** * Get error context */ public function getContext(): array { return $this->context; } /** * Get API error code */ public function getErrorCode(): string { return $this->errorCode; } /** * Set error context */ public function setContext(array $context): self { $this->context = $context; return $this; } /** * Add context data */ public function addContext(string $key, $value): self { $this->context[$key] = $value; return $this; } /** * Convert to array for API responses */ public function toArray(): array { return [ 'error_code' => $this->getErrorCode(), 'message' => $this->getMessage(), 'context' => $this->getContext(), 'file' => $this->getFile(), 'line' => $this->getLine(), ]; } }