API Exceptions ClientThrowable - evansims/openfga-php GitHub Wiki

Base interface for all OpenFGA SDK exceptions. Extends the standard PHP Throwable interface with additional methods to provide detailed context about SDK-specific errors including HTTP request/response information and categorized error types. This interface ensures consistent error handling across all exception types in the OpenFGA SDK, enabling developers to access rich context information for debugging and error reporting. All OpenFGA exceptions implement this interface to provide a unified error handling experience. OpenFGA exceptions are categorized into specific types: - Authentication errors (token expired, invalid credentials) - Configuration errors (missing PSR components, invalid setup) - Network errors (HTTP failures, timeouts, API unavailability) - Serialization errors (JSON parsing, schema validation failures) - Client errors (general validation and usage errors)

Table of Contents


Namespace

OpenFGA\Exceptions


Source

View source code


Implements

  • Throwable
  • Stringable


Methods

context

public function context(): array<string, mixed>

Get additional context information about the exception. Provides access to contextual data that was available when the exception occurred, such as parameter values, configuration details, API response data, or other relevant debugging information. This context is essential for understanding the circumstances that led to the error and can be used for logging, debugging, and error reporting.

View source


Returns

array&lt;string, mixed&gt; — Associative array of context data including parameter values, error details, and debugging information


getCode

public function getCode()

getFile

public function getFile(): string

Returns

string


getLine

public function getLine(): int

Returns

int


getMessage

public function getMessage(): string

Returns

string


getPrevious

public function getPrevious(): ?Throwable

Returns

Throwable | null


getTrace

public function getTrace(): array

Returns

array


getTraceAsString

public function getTraceAsString(): string

Returns

string


kind

public function kind(): AuthenticationError|ClientError|ConfigurationError|NetworkError|SerializationError

Get the specific error category for this exception. Returns the error classification that indicates the general category of the problem (authentication, configuration, network, etc.), allowing for categorized error handling and reporting. This categorization helps applications implement appropriate retry logic, user messaging, and error recovery strategies based on the type of failure.

View source


Returns

AuthenticationError | ClientError | ConfigurationError | NetworkError | SerializationError — The error category enum indicating the type of failure


previous

public function previous(): Throwable|null

Get the previous exception that caused this one. Provides access to the exception chain for cases where this exception was triggered by another underlying exception. This maintains the full context of error propagation and is essential for root cause analysis when exceptions are wrapped or transformed during processing.

View source


Returns

Throwable | null — The previous exception in the chain, or null if this is the root exception


request

public function request(): RequestInterface|null

Get the HTTP request associated with this exception. Returns the PSR-7 HTTP request that was being processed when this exception occurred. This is particularly useful for debugging API call failures, allowing developers to inspect the request URL, headers, body, and method that led to the error condition.

View source


Returns

RequestInterface | null — The PSR-7 HTTP request that triggered the exception, or null if not applicable


response

public function response(): ResponseInterface|null

Get the HTTP response associated with this exception. Returns the PSR-7 HTTP response that was received when this exception occurred, providing access to status codes, headers, and response body for debugging. This is especially valuable for understanding API-level failures and can contain detailed error messages from the OpenFGA service.

View source


Returns

ResponseInterface | null — The PSR-7 HTTP response received from the API, or null if no response was received

⚠️ **GitHub.com Fallback** ⚠️