Add fallback for single membership
This commit is contained in:
parent
4c33b9cbbc
commit
04d5e6f03a
|
@ -12,6 +12,7 @@ use Log;
|
|||
use Zoomyboy\LaravelNami\Backend\Backend;
|
||||
use Zoomyboy\LaravelNami\Concerns\IsNamiMember;
|
||||
use Zoomyboy\LaravelNami\Cookies\Cookie;
|
||||
use Zoomyboy\LaravelNami\Exceptions\RightException;
|
||||
use Zoomyboy\LaravelNami\NamiException;
|
||||
|
||||
class Api {
|
||||
|
@ -149,6 +150,10 @@ class Api {
|
|||
|
||||
Logger::http($url, $response, 'Single Membership '.$membershipId.' from '.$memberId, ['memberId' => $memberId]);
|
||||
|
||||
if($response->json()['success'] === false && Str::startsWith($response['message'], 'Sicherheitsverletzung')) {
|
||||
throw new RightException('');
|
||||
}
|
||||
|
||||
return $response->json()['data'];
|
||||
}
|
||||
|
||||
|
|
|
@ -2,15 +2,15 @@
|
|||
|
||||
namespace Zoomyboy\LaravelNami\Authentication;
|
||||
|
||||
use Illuminate\Contracts\Auth\Guard;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Zoomyboy\LaravelNami\Nami;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Zoomyboy\LaravelNami\NamiUser;
|
||||
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
|
||||
use Illuminate\Auth\SessionGuard;
|
||||
use Illuminate\Auth\GuardHelpers;
|
||||
use Illuminate\Auth\SessionGuard;
|
||||
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Contracts\Auth\Guard;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Str;
|
||||
use Zoomyboy\LaravelNami\Nami;
|
||||
use Zoomyboy\LaravelNami\NamiUser;
|
||||
|
||||
class NamiGuard {
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace Zoomyboy\LaravelNami\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class RightException extends Exception
|
||||
{
|
||||
|
||||
}
|
|
@ -5,6 +5,7 @@ namespace Zoomyboy\LaravelNami;
|
|||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\LazyCollection;
|
||||
use Zoomyboy\LaravelNami\Exceptions\RightException;
|
||||
|
||||
class Member extends Model {
|
||||
|
||||
|
@ -140,13 +141,23 @@ class Member extends Model {
|
|||
|
||||
return LazyCollection::make(function() use ($memberships) {
|
||||
foreach ($memberships as $membership) {
|
||||
yield $this->membership($membership['id']);
|
||||
$m = $this->membership($membership['id']);
|
||||
|
||||
if ($m === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
yield $m;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function membership($id): Membership {
|
||||
public function membership($id): ?Membership {
|
||||
try {
|
||||
return Membership::fromNami(Nami::membership($this->id, $id));
|
||||
} catch (RightException $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue