CoreFiles by mySites.guru
SaveExceptionHandler.php60 lines, 1,295 bytes, from Joomla_4.0.0-rc1-Release_Candidate-Full_Package.zip
Raw History Compare with 3.10.12-rc1
md5
eb3855261de827a1c45aadf6950fc2ee
sha1
583ebd63467c17ce342ef94b4cba982e55b9d24c
sha256
7f20c9bf3be2e73da5b8a3c53ae728ee193be1d74a2afd6393f77875c5610200
<?php
/**
 * Joomla! Content Management System
 *
 * @copyright  (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
 * @license    GNU General Public License version 2 or later; see LICENSE
 */

namespace Joomla\CMS\Error\JsonApi;

use Exception;
use Joomla\CMS\MVC\Controller\Exception\Save;
use Tobscure\JsonApi\Exception\Handler\ExceptionHandlerInterface;
use Tobscure\JsonApi\Exception\Handler\ResponseBag;

/**
 * Handler for invalid checkin/checkout exceptions
 *
 * @since  4.0.0
 */
class SaveExceptionHandler implements ExceptionHandlerInterface
{
	/**
	 * If the exception handler is able to format a response for the provided exception,
	 * then the implementation should return true.
	 *
	 * @param   \Exception  $e  The exception to be handled
	 *
	 * @return  boolean
	 *
	 * @since  4.0.0
	 */
	public function manages(Exception $e)
	{
		return $e instanceof Save;
	}

	/**
	 * Handle the provided exception.
	 *
	 * @param   Exception  $e  The exception being handled
	 *
	 * @return  \Tobscure\JsonApi\Exception\Handler\ResponseBag
	 *
	 * @since  4.0.0
	 */
	public function handle(Exception $e)
	{
		$status = 400;

		if ($e->getCode())
		{
			$status = $e->getCode();
		}

		$error = ['title' => $e->getMessage()];

		return new ResponseBag($status, [$error]);
	}
}

The same content is in 25 releases, Joomla 4.0.0-rc1 to 4.1.0-alpha3. See them all, or every version of this file.