MarketDataException
extends Exception
in package
Base exception class for all Market Data SDK exceptions.
This class provides common functionality for storing and retrieving request context including the request ID (cf-ray header), request URL, timestamp, and HTTP response. All SDK exception classes extend from this base.
Table of Contents
Properties
- $requestId : string|null
- $requestUrl : string|null
- $response : ResponseInterface|null
- $timestamp : DateTimeImmutable
Methods
- __construct() : mixed
- MarketDataException constructor.
- __toString() : string
- Get string representation of the exception.
- getRequestId() : string|null
- Get the Cloudflare request ID for support tickets.
- getRequestUrl() : string|null
- Get the URL that was requested when the error occurred.
- getResponse() : ResponseInterface|null
- Get the HTTP response associated with this exception.
- getSupportContext() : array{timestamp: string, request_id: string|null, url: string|null, http_code: int, message: string, exception_type: string}
- Get all support ticket context as an associative array.
- getSupportInfo() : string
- Get a pre-formatted string with all information needed for a support ticket.
- getTimestamp() : DateTimeImmutable
- Get the timestamp when the exception occurred.
- extractRequestId() : string|null
- Extract the request ID (cf-ray header) from the response.
Properties
$requestId
protected
string|null
$requestId
The Cloudflare request ID (cf-ray header) for support tickets.
$requestUrl
protected
string|null
$requestUrl
The URL that was requested when the error occurred.
$response
protected
ResponseInterface|null
$response
The HTTP response associated with this exception.
$timestamp
protected
DateTimeImmutable
$timestamp
The timestamp when the exception occurred (stored in UTC).
Methods
__construct()
MarketDataException constructor.
public
__construct([string $message = "" ][, int $code = 0 ][, Throwable|null $previous = null ][, ResponseInterface|null $response = null ][, string|null $requestUrl = null ]) : mixed
Parameters
- $message : string = ""
-
The exception message.
- $code : int = 0
-
The exception code.
- $previous : Throwable|null = null
-
The previous exception used for exception chaining.
- $response : ResponseInterface|null = null
-
The HTTP response associated with this exception.
- $requestUrl : string|null = null
-
The URL that was requested when the error occurred.
__toString()
Get string representation of the exception.
public
__toString() : string
Includes the standard exception information plus request context (timestamp, request ID, and URL) when available.
Return values
stringgetRequestId()
Get the Cloudflare request ID for support tickets.
public
getRequestId() : string|null
This ID can be provided to Market Data support to help identify the specific request that failed.
Return values
string|null —The request ID, or null if not available.
getRequestUrl()
Get the URL that was requested when the error occurred.
public
getRequestUrl() : string|null
Return values
string|null —The request URL, or null if not available.
getResponse()
Get the HTTP response associated with this exception.
public
getResponse() : ResponseInterface|null
Return values
ResponseInterface|null —The HTTP response.
getSupportContext()
Get all support ticket context as an associative array.
public
getSupportContext() : array{timestamp: string, request_id: string|null, url: string|null, http_code: int, message: string, exception_type: string}
This is useful for structured logging (JSON, log aggregation systems) or when you need to process the error details programmatically.
Example:
catch (MarketDataException $e) {
$logger->error('API Error', $e->getSupportContext());
}
Return values
array{timestamp: string, request_id: string|null, url: string|null, http_code: int, message: string, exception_type: string}getSupportInfo()
Get a pre-formatted string with all information needed for a support ticket.
public
getSupportInfo() : string
Copy and paste this output directly into your support request at support@marketdata.app or in the customer dashboard.
Example:
catch (MarketDataException $e) {
echo $e->getSupportInfo();
}
Return values
string —Formatted support ticket information.
getTimestamp()
Get the timestamp when the exception occurred.
public
getTimestamp() : DateTimeImmutable
The timestamp is stored in UTC. Convert to your preferred timezone as needed:
$localTime = $e->getTimestamp()->setTimezone(new \DateTimeZone('America/Los_Angeles'));
Return values
DateTimeImmutable —The timestamp when the exception was created (UTC).
extractRequestId()
Extract the request ID (cf-ray header) from the response.
protected
extractRequestId(ResponseInterface|null $response) : string|null
Parameters
- $response : ResponseInterface|null
-
The HTTP response.
Return values
string|null —The request ID, or null if not available.