private function fetchDirectory()
{
try {
/** @var Response $response */
$response = (yield $this->http->request($this->directoryUri));
if ($response->getStatus() !== 200) {
$info = json_decode($response->getBody());
if (isset($info->type, $info->detail)) {
throw new AcmeException("Invalid directory response: {$info->detail}", $info->type);
}
throw new AcmeException("Invalid directory response. HTTP response code: " . $response->getStatus());
}
$directory = json_decode($response->getBody(), true);
if (empty($directory)) {
throw new AcmeException("Invalid directory: empty!");
}
$this->directory = $directory;
$this->saveNonce($response);
} catch (Exception $e) {
throw new AcmeException("Could not obtain directory: " . $e->getMessage(), null, $e);
} catch (Throwable $e) {
throw new AcmeException("Could not obtain directory: " . $e->getMessage(), null, $e);
}
}