View file vendor/slim/slim/Slim/Error/AbstractErrorRenderer.php

File size: 1.17Kb
  1. <?php
  2.  
  3. /**
  4. * Slim Framework (https://slimframework.com)
  5. *
  6. * @license https://github.com/slimphp/Slim/blob/4.x/LICENSE.md (MIT License)
  7. */
  8.  
  9. declare(strict_types=1);
  10.  
  11. namespace Slim\Error;
  12.  
  13. use Slim\Exception\HttpException;
  14. use Slim\Interfaces\ErrorRendererInterface;
  15. use Throwable;
  16.  
  17. /**
  18. * Abstract Slim application error renderer
  19. *
  20. * It outputs the error message and diagnostic information in one of the following formats:
  21. * JSON, XML, Plain Text or HTML
  22. */
  23. abstract class AbstractErrorRenderer implements ErrorRendererInterface
  24. {
  25. protected string $defaultErrorTitle = 'Slim Application Error';
  26.  
  27. protected string $defaultErrorDescription = 'A website error has occurred. Sorry for the temporary inconvenience.';
  28.  
  29. protected function getErrorTitle(Throwable $exception): string
  30. {
  31. if ($exception instanceof HttpException) {
  32. return $exception->getTitle();
  33. }
  34.  
  35. return $this->defaultErrorTitle;
  36. }
  37.  
  38. protected function getErrorDescription(Throwable $exception): string
  39. {
  40. if ($exception instanceof HttpException) {
  41. return $exception->getDescription();
  42. }
  43.  
  44. return $this->defaultErrorDescription;
  45. }
  46. }