|
11 | 11 |
|
12 | 12 | class Statement implements \Iterator
|
13 | 13 | {
|
| 14 | + private const CLICKHOUSE_ERROR_REGEX = "%Code:\s(\d+)\.\s*DB::Exception\s*:\s*(.*)(?:,\s*e\.what|\(version).*%ius"; |
| 15 | + |
14 | 16 | /**
|
15 | 17 | * @var string|mixed
|
16 | 18 | */
|
@@ -133,23 +135,28 @@ public function sql()
|
133 | 135 | * @param string $body
|
134 | 136 | * @return array|bool
|
135 | 137 | */
|
136 |
| - private function parseErrorClickHouse($body) |
| 138 | + private function parseErrorClickHouse(string $body) |
137 | 139 | {
|
138 | 140 | $body = trim($body);
|
139 |
| - $mathes = []; |
| 141 | + $matches = []; |
140 | 142 |
|
141 | 143 | // Code: 115. DB::Exception: Unknown setting readonly[0], e.what() = DB::Exception
|
142 | 144 | // Code: 192. DB::Exception: Unknown user x, e.what() = DB::Exception
|
143 | 145 | // Code: 60. DB::Exception: Table default.ZZZZZ doesn't exist., e.what() = DB::Exception
|
144 | 146 | // Code: 516. DB::Exception: test_username: Authentication failed: password is incorrect or there is no user with such name. (AUTHENTICATION_FAILED) (version 22.8.3.13 (official build))
|
145 | 147 |
|
146 |
| - if (preg_match("%Code:\s(\d+).\s*DB\:\:Exception\s*:\s*(.*)(?:\,\s*e\.what|\(version).*%ius", $body, $mathes)) { |
147 |
| - return ['code' => $mathes[1], 'message' => $mathes[2]]; |
| 148 | + if (preg_match(self::CLICKHOUSE_ERROR_REGEX, $body, $matches)) { |
| 149 | + return ['code' => $matches[1], 'message' => $matches[2]]; |
148 | 150 | }
|
149 | 151 |
|
150 | 152 | return false;
|
151 | 153 | }
|
152 | 154 |
|
| 155 | + private function hasErrorClickhouse(string $body): bool { |
| 156 | + |
| 157 | + return preg_match(self::CLICKHOUSE_ERROR_REGEX, $body) === 1; |
| 158 | + } |
| 159 | + |
153 | 160 | /**
|
154 | 161 | * @return bool
|
155 | 162 | * @throws Exception\TransportException
|
@@ -197,12 +204,24 @@ public function error()
|
197 | 204 | * @return bool
|
198 | 205 | * @throws Exception\TransportException
|
199 | 206 | */
|
200 |
| - public function isError() |
| 207 | + public function isError(): bool |
201 | 208 | {
|
202 |
| - return ($this->response()->http_code() !== 200 || $this->response()->error_no()); |
| 209 | + if ($this->response()->http_code() !== 200) { |
| 210 | + return true; |
| 211 | + } |
| 212 | + |
| 213 | + if ($this->response()->error_no()) { |
| 214 | + return true; |
| 215 | + } |
| 216 | + |
| 217 | + if ($this->hasErrorClickhouse($this->response()->body())) { |
| 218 | + return true; |
| 219 | + } |
| 220 | + |
| 221 | + return false; |
203 | 222 | }
|
204 | 223 |
|
205 |
| - private function check() : bool |
| 224 | + private function check(): bool |
206 | 225 | {
|
207 | 226 | if (!$this->_request->isResponseExists()) {
|
208 | 227 | throw QueryException::noResponse();
|
|
0 commit comments