Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function responseInterceptor()
- {
- return function (callable $handler) {
- return function (
- RequestInterface $request,
- array $options
- ) use ($handler) {
- $promise = $handler($request, $options);
- return $promise->then(
- function (ResponseInterface $response){
- if($response->getStatusCode() == 401){
- $auth = new \ILT\Auth();
- $tokenStatus = $auth->refresh_token();
- if(isset($tokenStatus->error) ){
- $response = new \GuzzleHttp\Psr7\Response(
- 401,
- ["'Content-Type' = 'application/json'"],
- json_encode($tokenStatus)
- );
- }else{
- $response = new \GuzzleHttp\Psr7\Response(
- 401,
- ["'Content-Type' = 'application/json'"],
- json_encode([
- 'error' => 'permission_denied',
- 'error_description' => 'Token expired',
- ]
- ));
- }
- }
- return $response;
- }
- );
- };
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement