From a317215554e093e7499d823d136d6e0a81e4d505 Mon Sep 17 00:00:00 2001 From: Philipp Lang Date: Tue, 15 Sep 2020 23:42:18 +0000 Subject: [PATCH] Add namiException when fetching of member returns error --- src/Api.php | 21 +++++++++++++++------ src/NamiException.php | 18 ++++++++++++++++++ 2 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 src/NamiException.php diff --git a/src/Api.php b/src/Api.php index e451a85..138b87d 100644 --- a/src/Api.php +++ b/src/Api.php @@ -112,15 +112,24 @@ class Api { Logger::http($url, $response, 'Show member '.$memberId, ['memberId' => $memberId]); - if ($response->json()['success'] === true) { - return $response->json()['data']; - } - - if(Str::startsWith($response['message'], 'Access denied')) { + if($response->json()['success'] === false && Str::startsWith($response['message'], 'Access denied')) { return $this->singleMemberFallback($groupId, $memberId); } - return $response->json()['data']; + if($response->json()['success'] === false && Str::startsWith($response['message'], 'Sicherheitsverletzung: Zugriff')) { + return $this->singleMemberFallback($groupId, $memberId); + } + + if ($response->json()['success'] === true) { + return $response->json()['data']; + } else { + $e = new NamiException('Fetch von Mitglied fehlgeschlagen'); + $e->setData([ + 'response' => $response->body(), + 'url' => $url + ]); + throw $e; + } } public function hasGroup($groupId): bool { diff --git a/src/NamiException.php b/src/NamiException.php new file mode 100644 index 0000000..68a6aaf --- /dev/null +++ b/src/NamiException.php @@ -0,0 +1,18 @@ +data = $data; + } + + public function getData() { + return $this->data; + } +}