diff --git a/src/Services/AbstractRdapService.php b/src/Services/AbstractRdapService.php index 43dbfef..a3c6103 100644 --- a/src/Services/AbstractRdapService.php +++ b/src/Services/AbstractRdapService.php @@ -394,7 +394,9 @@ public static function fromURL(string $url) : static && is_writable(dirname($fileCache)) ? $fileCache : null; } } - set_error_handler(static function (int $code, string $message, string $file, int $line) : bool { + $errorMessage = null; + set_error_handler(static function (int $code, string $message) use (&$errorMessage) : bool { + $errorMessage ??= $message; error_clear_last(); return true; }); @@ -406,8 +408,17 @@ public static function fromURL(string $url) : static ) : null ); restore_error_handler(); + if (!is_string($content)) { + throw new InvalidServiceDefinitionException( + sprintf( + 'Could not fetch protocol service URL "%s": %s', + $url, + $errorMessage ?? 'unknown error' + ) + ); + } - $service = static::fromJson(is_string($content) ? $content : '', $url); + $service = static::fromJson($content, $url); if ($fileCache) { file_put_contents($fileCache, $content); }