[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/Error/JsonApi/ -> InvalidParameterExceptionHandler.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
   7   * @license    GNU General Public License version 2 or later; see LICENSE
   8   */
   9  
  10  namespace Joomla\CMS\Error\JsonApi;
  11  
  12  use Exception;
  13  use Tobscure\JsonApi\Exception\Handler\ResponseBag;
  14  
  15  // phpcs:disable PSR1.Files.SideEffects
  16  \defined('JPATH_PLATFORM') or die;
  17  // phpcs:enable PSR1.Files.SideEffects
  18  
  19  /**
  20   * Handler for invalid param
  21   *
  22   * @since  4.0.0
  23   */
  24  class InvalidParameterExceptionHandler extends \Tobscure\JsonApi\Exception\Handler\InvalidParameterExceptionHandler
  25  {
  26      /**
  27       * Handle the provided exception.
  28       *
  29       * @param   Exception  $e  The exception being handled
  30       *
  31       * @return  \Tobscure\JsonApi\Exception\Handler\ResponseBag
  32       *
  33       * @since  4.0.0
  34       */
  35      public function handle(Exception $e)
  36      {
  37          $status = 400;
  38          $error = ['title' => $e->getMessage()];
  39  
  40          $code = $e->getCode();
  41  
  42          if ($code) {
  43              $error['code'] = $code;
  44          }
  45  
  46          return new ResponseBag($status, [$error]);
  47      }
  48  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer