tryResponse( context: $context, fn: function () use ($context, $opts) { $url = $context->backendUrl->withPath('/'); $this->logger->debug('Requesting [{client}: {backend}] unique identifier.', [ 'client' => $context->clientName, 'backend' => $context->backendName, 'url' => $url ]); $response = $this->http->request( 'GET', (string)$url, array_replace_recursive($context->backendHeaders, $opts['headers'] ?? []) ); $content = $response->getContent(false); if (200 !== $response->getStatusCode()) { return new Response( status: false, error: new Error( message: 'Request for [{backend}] {action} returned with unexpected [{status_code}] status code.', context: [ 'action' => $this->action, 'client' => $context->clientName, 'backend' => $context->backendName, 'status_code' => $response->getStatusCode(), 'url' => (string)$url, 'response' => $content, ], level: Levels::WARNING ) ); } if (empty($content)) { return new Response( status: false, error: new Error( message: 'Request for [{backend}] {action} returned with empty response. Please make sure the container can communicate with the backend.', context: [ 'action' => $this->action, 'client' => $context->clientName, 'backend' => $context->backendName, 'url' => (string)$url, 'response' => $content, ], level: Levels::ERROR ) ); } $item = json_decode( json: $content, associative: true, flags: JSON_THROW_ON_ERROR | JSON_INVALID_UTF8_IGNORE ); if (true === $context->trace) { $this->logger->debug('Processing [{client}: {backend}] {action} payload.', [ 'action' => $this->action, 'client' => $context->clientName, 'backend' => $context->backendName, 'trace' => $item, ]); } $data = ag($item, 'MediaContainer', []); $ret = [ 'type' => $context->clientName, 'name' => ag($data, 'friendlyName', null), 'version' => ag($data, 'version', null), 'identifier' => ag($data, 'machineIdentifier', null), 'platform' => ag($data, 'platform', null), ]; if (true === ag_exists($opts, Options::RAW_RESPONSE)) { $ret[Options::RAW_RESPONSE] = $data; } return new Response( status: true, response: $ret, ); }, action: $this->action ); } }