1: <?php
2: /**
3: * This code is licensed under AGPLv3 license or Afterlogic Software License
4: * if commercial version of the product was purchased.
5: * For full statements of the licenses see LICENSE-AFTERLOGIC and LICENSE-AGPL3 files.
6: */
7:
8: namespace Aurora\System\Exceptions;
9:
10: /**
11: * @license https://www.gnu.org/licenses/agpl-3.0.html AGPL-3.0
12: * @license https://afterlogic.com/products/common-licensing Afterlogic Software License
13: * @copyright Copyright (c) 2022, Afterlogic Corp.
14: *
15: * @package Api
16: */
17: class BaseException extends Exception
18: {
19: /**
20: * @var array
21: */
22: protected $aObjectParams;
23:
24: /**
25: * @var Exception
26: */
27: protected $oPrevious;
28:
29: /**
30: * @param int $iCode
31: * @param Exception $oPrevious = null
32: * @param array $aParams = array()
33: * @param array $aObjectParams = array()
34: */
35: public function __construct($iCode, $oPrevious = null, $aParams = array(), $aObjectParams = array())
36: {
37: if (\Aurora\System\Exceptions\ErrorCodes::Validation_FieldIsEmpty === $iCode) {
38: \Aurora\System\Api::Log('Exception error: '.\Aurora\System\Exceptions\ErrorCodes::GetMessageByCode($iCode, $aParams), \Aurora\System\Enums\LogLevel::Error);
39: $iCode = \Aurora\System\Exceptions\ErrorCodes::Validation_FieldIsEmpty_OutInfo;
40: }
41:
42: $this->aObjectParams = $aObjectParams;
43: $this->oPrevious = $oPrevious ? $oPrevious : null;
44:
45: if ($this->oPrevious) {
46: \Aurora\System\Api::Log('Previous Exception: '.$this->oPrevious->getMessage(), \Aurora\System\Enums\LogLevel::Error);
47: }
48:
49: parent::__construct(\Aurora\System\Exceptions\ErrorCodes::GetMessageByCode($iCode, $aParams), $iCode);
50: }
51:
52: /**
53: * @return array
54: */
55: public function GetObjectParams()
56: {
57: return $this->aObjectParams;
58: }
59:
60: /**
61: * @return string
62: */
63: public function GetPreviousMessage()
64: {
65: $sMessage = '';
66: if ($this->oPrevious instanceof \MailSo\Imap\Exceptions\NegativeResponseException) {
67: $oResponse = /* @var $oResponse \MailSo\Imap\Response */ $this->oPrevious->GetLastResponse();
68:
69: $sMessage = $oResponse instanceof \MailSo\Imap\Response ?
70: $oResponse->Tag.' '.$oResponse->StatusOrIndex.' '.$oResponse->HumanReadable : '';
71: } elseif ($this->oPrevious instanceof \MailSo\Smtp\Exceptions\NegativeResponseException) {
72: $sMessage = $this->oPrevious->getMessage();
73: // $oSub = $this->oPrevious->getPrevious();
74: // $oSub = $oSub instanceof \MailSo\Smtp\Exceptions\NegativeResponseException ? $oSub : null;
75: //
76: // $sMessage = $oSub ? $oSub->getMessage() : $this->oPrevious->getMessage();
77: } elseif ($this->oPrevious instanceof \Exception) {
78: $sMessage = $this->oPrevious->getMessage();
79: }
80:
81: return $sMessage;
82: }
83:
84: /**
85: * @return string
86: */
87: public function GetPreviousException()
88: {
89: return $this->oPrevious;
90: }
91: }
92: