CoreFiles by mySites.guru
InvalidParameterExceptionHandler.php47 lines, 1,025 bytes, from Joomla_4.2.6-Stable-Full_Package.zip
Raw History Compare with 4.2.5
md5
be7ce1a78b155a268afcfa3770d7f219
sha1
3ce404241758c68f0bbcc86b77ec4d3c0994a352
sha256
3927c61424a326c3ddba9c4a7e70b004cfc4884da242915812d6de7d562c65b6
<?php

/*
 * This file is part of JSON-API.
 *
 * (c) Toby Zerner <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Tobscure\JsonApi\Exception\Handler;

use Exception;
use Tobscure\JsonApi\Exception\InvalidParameterException;

class InvalidParameterExceptionHandler implements ExceptionHandlerInterface
{
    /**
     * {@inheritdoc}
     */
    public function manages(Exception $e)
    {
        return $e instanceof InvalidParameterException;
    }

    /**
     * {@inheritdoc}
     */
    public function handle(Exception $e)
    {
        $status = 400;
        $error = [];

        $code = $e->getCode();
        if ($code) {
            $error['code'] = $code;
        }

        $invalidParameter = $e->getInvalidParameter();
        if ($invalidParameter) {
            $error['source'] = ['parameter' => $invalidParameter];
        }

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

The same content is in 295 releases, Joomla 4.0.0-alpha7 to 6.3.0-alpha1. See them all, or every version of this file.