Skip to content

Commit 4d299eb

Browse files
authored
Added required error message.
If any JSON error occurs user will be be shown error message if the app mode is not in Production.
1 parent 25fb501 commit 4d299eb

File tree

1 file changed

+20
-2
lines changed
  • lib/internal/Magento/Framework/Serialize/Serializer

1 file changed

+20
-2
lines changed

lib/internal/Magento/Framework/Serialize/Serializer/Json.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
*/
1616
class Json implements SerializerInterface
1717
{
18+
private $appState = NULL;
19+
20+
public function __construct(){
21+
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
22+
$this->appState = $this->objectmanager->get('Magento\Framework\App\State');
23+
}
1824
/**
1925
* {@inheritDoc}
2026
* @since 100.2.0
@@ -23,7 +29,11 @@ public function serialize($data)
2329
{
2430
$result = json_encode($data);
2531
if (false === $result) {
26-
throw new \InvalidArgumentException('Unable to serialize value.');
32+
$errorMessage = "Unable to serialize value.";
33+
if(!$this->isOnProduction()){
34+
$errorMessage .= "Error: " . json_last_error_msg();
35+
}
36+
throw new \InvalidArgumentException($errorMessage);
2737
}
2838
return $result;
2939
}
@@ -36,8 +46,16 @@ public function unserialize($string)
3646
{
3747
$result = json_decode($string, true);
3848
if (json_last_error() !== JSON_ERROR_NONE) {
39-
throw new \InvalidArgumentException('Unable to unserialize value.');
49+
$errorMessage = "Unable to unserialize value.";
50+
if(!$this->isOnProduction()){
51+
$errorMessage .= "Error: " . json_last_error_msg();
52+
}
53+
throw new \InvalidArgumentException($errorMessage);
4054
}
4155
return $result;
4256
}
57+
58+
private function isOnProduction(){
59+
return $this->appState === \Magento\Framework\App\State::MODE_PRODUCTION;
60+
}
4361
}

0 commit comments

Comments
 (0)