| @@ -1,0 +1,36 @@ | ||
| 1 | +<?php | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * @copyright © Melograno Venture Studio. All rights reserved. | |
| 5 | + * @licence See LICENCE.md for license details. | |
| 6 | + */ | |
| 7 | + | |
| 8 | +namespace IvyForms\Common\Exceptions; | |
| 9 | + | |
| 10 | +use Exception; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * Class ForbiddenException | |
| 14 | + * | |
| 15 | + * Handled by Controller to return a JSON 403 REST response. | |
| 16 | + * | |
| 17 | + * @package IvyForms\Common\Exceptions | |
| 18 | + */ | |
| 19 | +class ForbiddenException extends Exception | |
| 20 | +{ | |
| 21 | + /** | |
| 22 | + * ForbiddenException constructor. | |
| 23 | + * | |
| 24 | + * @param string $message | |
| 25 | + * @param int $code | |
| 26 | + * @param Exception|null $previous | |
| 27 | + */ | |
| 28 | + public function __construct($message = '', $code = 403, ?Exception $previous = null) | |
| 29 | + { | |
| 30 | + if ($message === '' || $message === 'forbidden') { | |
| 31 | + $message = esc_html__('You do not have permission to access this page.', 'ivyforms'); | |
| 32 | + } | |
| 33 | + | |
| 34 | + parent::__construct($message, $code, $previous); | |
| 35 | + } | |
| 36 | +} | |