From f89253e9de9ad6e3a08179b3387540d5afea123b Mon Sep 17 00:00:00 2001 From: Mohamed Nagy Date: Fri, 1 Sep 2023 15:25:24 +0200 Subject: [PATCH] make ApiError json serializable --- .gitignore | 1 + lib/Exceptions/ApiError.php | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index e75107a..88e80d8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ vendor .php-cs-fixer.cache .phpunit.result.cache composer.lock +.idea/ diff --git a/lib/Exceptions/ApiError.php b/lib/Exceptions/ApiError.php index 7b5bf9c..30944c3 100644 --- a/lib/Exceptions/ApiError.php +++ b/lib/Exceptions/ApiError.php @@ -2,7 +2,9 @@ namespace AboutYou\Cloud\AdminApi\Exceptions; -class ApiError +use JsonSerializable; + +class ApiError implements JsonSerializable { /** * @var string @@ -49,4 +51,16 @@ public function getContext() { return $this->context; } + + /** + * @return array + */ + public function jsonSerialize() + { + return [ + 'errorKey' => $this->errorKey, + 'message' => $this->message, + 'context' => $this->context, + ]; + } }