Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. function responseInterceptor()
  2. {
  3. return function (callable $handler) {
  4. return function (
  5. RequestInterface $request,
  6. array $options
  7. ) use ($handler) {
  8. $promise = $handler($request, $options);
  9. return $promise->then(
  10. function (ResponseInterface $response){
  11. if($response->getStatusCode() == 401){
  12.  
  13. $auth = new \ILT\Auth();
  14.  
  15. $tokenStatus = $auth->refresh_token();
  16.  
  17. if(isset($tokenStatus->error) ){
  18. $response = new \GuzzleHttp\Psr7\Response(
  19. 401,
  20. ["'Content-Type' = 'application/json'"],
  21. json_encode($tokenStatus)
  22. );
  23. }else{
  24.  
  25. $response = new \GuzzleHttp\Psr7\Response(
  26. 401,
  27. ["'Content-Type' = 'application/json'"],
  28. json_encode([
  29. 'error' => 'permission_denied',
  30. 'error_description' => 'Token expired',
  31. ]
  32. ));
  33. }
  34.  
  35.  
  36. }
  37. return $response;
  38. }
  39. );
  40. };
  41. };
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement