fixed:捕获异常以Json方式返回

This commit is contained in:
JaguarJack 2021-01-20 20:12:08 +08:00
parent 65d3111e65
commit 340e8c356b

View File

@ -63,25 +63,30 @@ class CatchUpload
*/ */
public function upload(UploadedFile $file): string public function upload(UploadedFile $file): string
{ {
$this->initUploadConfig(); try {
$this->initUploadConfig();
$path = Filesystem::disk($this->getDriver())->putFile($this->getPath(), $file); $path = Filesystem::disk($this->getDriver())->putFile($this->getPath(), $file);
if ($path) { if ($path) {
$url = self::getCloudDomain($this->getDriver()) . '/' . $this->getLocalPath($path); $url = self::getCloudDomain($this->getDriver()) . '/' . $this->getLocalPath($path);
event('attachment', [ event('attachment', [
'path' => $path, 'path' => $path,
'url' => $url, 'url' => $url,
'driver' => $this->getDriver(), 'driver' => $this->getDriver(),
'file' => $file, 'file' => $file,
]); ]);
return $url; return $url;
}
throw new FailedException('Upload Failed, Try Again!');
} catch (\Exception $exception) {
throw new FailedException($exception->getMessage());
} }
throw new FailedException('Upload Failed, Try Again!');
} }
/** /**