Add AuthorizationException handling
This commit is contained in:
parent
27ed472922
commit
9833b14866
2 changed files with 18 additions and 0 deletions
|
|
@ -51,6 +51,13 @@ use Kwaadpepper\Enum\BaseEnum;
|
|||
* Too many requests have been attempted. The is a throttle security.
|
||||
* Normally you should not trigger this.
|
||||
* If this happens fill a ticket on https://supportweb.ldc.fr
|
||||
* with some technical details
|
||||
*
|
||||
* @method static self authorizationException()
|
||||
* You are maybe trying to access data that is out of your range.
|
||||
* This should not happen normally, it is here to allow you to handle this case.
|
||||
* If this happens fill a ticket on https://supportweb.ldc.fr
|
||||
* with some technical details
|
||||
*
|
||||
* @package LDCCrmClient
|
||||
* @subpackage enums
|
||||
|
|
@ -71,6 +78,7 @@ class ApiError extends BaseEnum
|
|||
'singleOptinCustomerExists' => 120,
|
||||
'methodNotAllowed' => 150,
|
||||
'wrongTimeStamp' => 151,
|
||||
'authorizationException' => 403,
|
||||
'throttleRequestsException' => 429
|
||||
];
|
||||
}
|
||||
|
|
@ -88,6 +96,7 @@ class ApiError extends BaseEnum
|
|||
'needAuth' => trans('You need to be authenticated'),
|
||||
'methodNotAllowed' => trans('This method is not allowed for this request'),
|
||||
'wrongTimeStamp' => trans('Your request is malformed, please check timestamp header and parameter'),
|
||||
'authorizationException' => trans('You are not autorized to access this'),
|
||||
'throttleRequestsException' => trans('Throttle: too many request have been attempted, please retry later')
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ use App\Exceptions\Api\V2\CrmException;
|
|||
use App\Http\Resources\Api\V2\ApiResponse as V2ApiResponse;
|
||||
use App\Lib\Helper;
|
||||
use App\Mail\ExceptionAlert;
|
||||
use Illuminate\Auth\Access\AuthorizationException;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
|
|
@ -143,6 +144,14 @@ class Handler extends ExceptionHandler
|
|||
ApiError::throttleRequestsException()->value,
|
||||
ApiError::throttleRequestsException()->label
|
||||
);
|
||||
case AuthorizationException::class:
|
||||
/** @var AuthorizationException $e */
|
||||
return $this->getReponse(
|
||||
$request,
|
||||
403,
|
||||
ApiError::authorizationException()->value,
|
||||
ApiError::authorizationException()->label
|
||||
);
|
||||
case CrmException::class:
|
||||
default:
|
||||
if (config('app.env') === 'testing') {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue