SHARE
TWEET

Error handler

unnamed1233 Nov 13th, 2019 113 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3.  
  4. declare(strict_types = 1);
  5.  
  6.  
  7. namespace Controllers;
  8.  
  9.  
  10. use Loger\Log;
  11. use Psr\Http\Message\ServerRequestInterface;
  12. use Slim\Exception\HttpNotFoundException;
  13. use Throwable;
  14. use Core\Main;
  15.  
  16.  
  17. class ErrorHandler
  18. {
  19.     function __invoke(ServerRequestInterface $request, Throwable $exception, bool $displayErrorDetails, bool $logErrors, bool $logErrorDetails)
  20.     {
  21.         Log::addInfo('work!');
  22.         $payload = ['error' => $exception->getMessage(), 'file' => $exception->getFile(), 'line' => $exception->getLine()];
  23.  
  24.         $response = Main::$app->getResponseFactory()->createResponse();
  25.         $response->getBody()->write(
  26.             json_encode($payload, JSON_UNESCAPED_UNICODE)
  27.         );
  28.  
  29.         return $response;
  30.     }
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top