From 8d21a16fc3d699632d50725b85209de599e44597 Mon Sep 17 00:00:00 2001 From: augushong <31880431+augushong@users.noreply.github.com> Date: Thu, 21 Dec 2023 22:26:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84read=E6=96=B9=E6=B3=95file=5F?= =?UTF-8?q?get=5Fcontent=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 有时候file_get_content会出现错误,会直接抛出异常,从而无法正确的抛出对应的异常UnableToReadFile。因此需要捕获file_get_content的异常或者增加错误抑制符,这里对齐增加异常捕获 --- src/QiniuAdapter.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/QiniuAdapter.php b/src/QiniuAdapter.php index 755ca53..6cd6246 100644 --- a/src/QiniuAdapter.php +++ b/src/QiniuAdapter.php @@ -80,7 +80,12 @@ public function writeStream(string $path, $contents, Config $config): void public function read(string $path): string { - $result = file_get_contents($this->privateDownloadUrl($path)); + try { + $result = file_get_contents($this->privateDownloadUrl($path)); + } catch (\Exception $th) { + throw UnableToReadFile::fromLocation($path); + } + if (false === $result) { throw UnableToReadFile::fromLocation($path); }