Add namiException when fetching of member returns error

This commit is contained in:
Philipp Lang 2020-09-15 23:42:18 +00:00
parent 88076d2e1d
commit a317215554
2 changed files with 33 additions and 6 deletions

View File

@ -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 {

18
src/NamiException.php Normal file
View File

@ -0,0 +1,18 @@
<?php
namespace Zoomyboy\LaravelNami;
use Illuminate\Support\Str;
class NamiException extends \Exception {
private $data;
public function setData($data) {
$this->data = $data;
}
public function getData() {
return $this->data;
}
}