Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
restexception.php
1<?
2namespace Bitrix\Rest;
3
5 extends \Exception
6{
7 const ERROR_INTERNAL_WRONG_TRANSPORT = 'INTERNAL_WRONG_TRANSPORT';
8 const ERROR_INTERNAL_WRONG_HANDLER_CLASS = 'INTERNAL_WRONG_HANDLER_CLASS';
9 const ERROR_INTERNAL_WRONG_FILE_HANDLER = 'INTERNAL_WRONG_FILE_HANDLER';
10 const ERROR_INTERNAL_PORTAL_DELETED = 'PORTAL_DELETED';
11
12 const ERROR_OAUTH = 'ERROR_OAUTH';
13 const ERROR_METHOD_NOT_FOUND = 'ERROR_METHOD_NOT_FOUND';
14 const ERROR_OPERATION_TIME_LIMIT = 'OPERATION_TIME_LIMIT';
15 const ERROR_CORE = 'ERROR_CORE';
16 const ERROR_ARGUMENT = 'ERROR_ARGUMENT';
17 const ERROR_NOT_FOUND = 'ERROR_NOT_FOUND';
18
19 protected $status;
20 protected $error_code;
21 protected $error_additional = array();
22
23 public function __construct($message, $code = "", $status = 0, \Exception $previous = null)
24 {
25 $this->status = $status;
26 $this->error_code = $code;
27 $message = strval($message);
28
29 parent::__construct($message, intval($code), $previous);
30 }
31
32 public function getErrorCode()
33 {
34 return $this->error_code;
35 }
36
37 public function setErrorCode($error_code)
38 {
39 $this->error_code = $error_code;
40 $this->code = intval($error_code);
41 }
42
43 public function getStatus()
44 {
45 return $this->status == 0 ? \CRestServer::STATUS_WRONG_REQUEST : $this->status;
46 }
47
48 public function setStatus($status)
49 {
50 $this->status = $status;
51 }
52
53 public function setMessage($msg)
54 {
55 $this->message = $msg;
56 }
57
58 public function getAdditional()
59 {
61 }
62
64 {
65 $this->error_additional = $error_additional;
66 }
67
68 public function setApplicationException(\CApplicationException $ex)
69 {
70 if($ex->getId())
71 {
72 $this->setErrorCode($ex->getId());
73 }
74 else
75 {
76 $this->setErrorCode(self::ERROR_CORE);
77 }
78
79 $this->message = $ex->getString();
80 }
81
82 public static function initFromException(\Exception $e)
83 {
84 $ex = null;
85
86 if (is_a($e, '\Bitrix\Main\DB\SqlException'))
87 {
88 $ex = new self(
89 "SQL query error!",
91 \CRestServer::STATUS_INTERNAL,
92 $e->getPrevious()
93 );
94 }
95 elseif(is_a($e, '\Bitrix\Main\SystemException'))
96 {
97 if(is_a($e, '\Bitrix\Main\ArgumentException'))
98 {
99 $ex = new self(
100 $e->getMessage(),
102 \CRestServer::STATUS_WRONG_REQUEST,
103 $e->getPrevious()
104 );
105
106 $ex->setAdditional(array(
107 "argument" => $e->getParameter(),
108 ));
109 }
110 }
111
112 if(!$ex)
113 {
114 $ex = new self(
115 $e->getMessage(),
116 $e->getCode() ? $e->getCode() : self::ERROR_CORE,
117 \CRestServer::STATUS_WRONG_REQUEST,
118 $e->getPrevious()
119 );
120 }
121
122 return $ex;
123 }
124}
125?>
__construct($message, $code="", $status=0, \Exception $previous=null)
setApplicationException(\CApplicationException $ex)
setAdditional($error_additional)
static initFromException(\Exception $e)