Skip to content

Commit 7f4ce19

Browse files
committed
Add more error handling in Config::loadJson()
1 parent fb2283d commit 7f4ce19

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/Libraries/Core/Config.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,17 @@ public static function loadJson(): bool
110110
return false;
111111
}
112112

113-
self::$json_config = \json_decode(
114-
\file_get_contents(self::JSON_CONFIG_PATH), true, self::JSON_FLAGS
115-
);
113+
$buffer = \file_get_contents(self::JSON_CONFIG_PATH);
114+
if ($buffer === false)
115+
{
116+
throw new \UnexpectedValueException('Cannot retrieve application JSON configuration');
117+
}
118+
self::$json_config = \json_decode($buffer, true, self::JSON_FLAGS);
119+
$json_errno = \json_last_error();
120+
if ($json_errno != \JSON_ERROR_NONE)
121+
{
122+
throw new \JsonException(\json_last_error_msg(), $json_errno);
123+
}
116124

117125
return true;
118126
}

0 commit comments

Comments
 (0)