A super easy PHP Framework for web development! https://github.com/exacti/phacil-framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.6 KiB

<?php
/**
* Copyright © 2023 ExacTI Technology Solutions. All rights reserved.
* GPLv3 General License.
* https://exacti.com.br
* Phacil PHP Framework - https://github.com/exacti/phacil-framework
*/
namespace Phacil\Framework\Exception;
/**
* Exception for Rest API
9 months ago
*
* @package Phacil\Framework\Exception
9 months ago
* @since 2.0.0
* @api
*/
class WebApiException extends \Phacil\Framework\Exception {
/**
* Error HTTP response codes.
*/
const HTTP_BAD_REQUEST = 400;
const HTTP_UNAUTHORIZED = 401;
const HTTP_FORBIDDEN = 403;
const HTTP_NOT_FOUND = 404;
const HTTP_METHOD_NOT_ALLOWED = 405;
const HTTP_NOT_ACCEPTABLE = 406;
const HTTP_INTERNAL_ERROR = 500;
/**
* Fault codes that are used in SOAP faults.
*/
const FAULT_CODE_SENDER = 'Sender';
const FAULT_CODE_RECEIVER = 'Receiver';
/**
* @var \Phacil\Framework\Config
*/
private $config;
protected $exceptionFile = \Phacil\Framework\Exception\Throwable::DEFAULT_WEBEXCEPTION_FILE;
/**
* Construct the exception. Note: The message is NOT binary safe.
*
* @param string|array $message
* @param int $code
* @param \Phacil\Framework\Exception\Throwable|null $previous
* @return void
*/
public function __construct($message = "", int $code = 400, $previous = null) {
/** @var \Phacil\Framework\Config */
$this->config = \Phacil\Framework\Registry::getInstance(\Phacil\Framework\Config::class);
parent::__construct((is_array($message) ? \Phacil\Framework\Json::encode($message) : $message), $code, $previous);
}
public function __destruct() {
if($this->config->get('config_registry_webexceptions'))
parent::__destruct();
}
}