$endpoint, 'timeout' => $timeout, ) ); } /** * Create exception for invalid credentials * * @since 1.0.0 * @param string $api_name API name. * @return self. */ public static function invalid_credentials( string $api_name ): self { return new self( 'Invalid API credentials provided', 401, null, array( 'api_name' => $api_name ) ); } /** * Create exception for rate limit exceeded * * @since 1.0.0 * @param int $retry_after Retry after seconds. * @return self. */ public static function rate_limit_exceeded( int $retry_after = 0 ): self { return new self( 'API rate limit exceeded', 429, null, array( 'retry_after' => $retry_after ) ); } /** * Create exception for network error * * @since 1.0.0 * @param string $error_message Network error message. * @return self. */ public static function network_error( string $error_message ): self { return new self( 'Network error occurred during API request', 500, null, array( 'network_error' => $error_message ) ); } /** * Create exception for invalid response * * @since 1.0.0 * @param string $response_body Response body. * @param int $status_code HTTP status code. * @return self. */ public static function invalid_response( string $response_body, int $status_code ): self { return new self( 'Invalid API response received', $status_code, null, array( 'status_code' => $status_code, 'response_preview' => substr( $response_body, 0, 200 ), ) ); } }