From 0b77296d45c62449a1cdd8a17004647080645984 Mon Sep 17 00:00:00 2001 From: Thomas Templeton Date: Wed, 17 Feb 2021 17:51:06 +1100 Subject: [PATCH] Fix #160 --- CHANGELOG.md | 3 +++ src/Service.php | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74f5283..a40debe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ ### Changed - The embedded asset caching added in Embedded Assets 2.3.0 now uses the Craft data cache, rather than manual saving of files within `storage/runtime/assets/embeddedassets` (thanks @johndwells) +### Fixed +- Fixed a potential error when trying to get the `EmbeddedAsset` model of an asset that wasn't an embedded asset + ## 2.4.5 - 2020-12-29 ### Changed diff --git a/src/Service.php b/src/Service.php index fea20cf..eb74a55 100644 --- a/src/Service.php +++ b/src/Service.php @@ -645,7 +645,13 @@ static function() use($asset) { }, 0); - return Json::decodeIfJson($contents); + try { + $contents = Json::decode($contents); + } catch (\Throwable $e) { + throw new Exception('Tried to get the contents of a non-embedded asset'); + } + + return $contents; } /**