= 300) { $slack = new slack(); $urlParts = parse_url($url); $safeEndpoint = (string)($urlParts['host'] ?? 'unknown-host') . (string)($urlParts['path'] ?? ''); $slack->send_message( 'XLVask API Request Failed', "Endpoint: {$safeEndpoint}\nMethod: {$method}\nHTTP Code: {$httpCode}\n" . 'Request fields: ' . count($data) . "\nResponse bytes: " . strlen((string)$response) ); throw new \Exception('Request failed with status code ' . $httpCode); } // Check if the response is valid JSON $responseData = json_decode($response, true); if (json_last_error() !== JSON_ERROR_NONE) { // Check if the response is empty (which is valid) if ($response === '') { return []; } throw new \Exception('Invalid JSON response: ' . json_last_error_msg()); } // Return the response data return $responseData; } /** * @inheritDoc */ public function generateBasicAuthHeader(string $username, string $password): string { return 'Authorization: Basic ' . base64_encode($username . ':' . $password); } }