|
4 | 4 |
|
5 | 5 | use Ehann\RediSearch\Exceptions\InvalidRedisClientClassException;
|
6 | 6 | use Ehann\RediSearch\Exceptions\UnknownIndexNameException;
|
| 7 | +use Ehann\RediSearch\Exceptions\UnknownRediSearchCommandException; |
7 | 8 | use Ehann\RediSearch\Exceptions\UnsupportedLanguageException;
|
8 | 9 | use Psr\Log\LoggerInterface;
|
9 | 10 |
|
@@ -72,16 +73,24 @@ public function rawCommand(string $command, array $arguments)
|
72 | 73 | $rawResult = $this->isPredisClient() ?
|
73 | 74 | $this->redis->executeRaw($arguments) :
|
74 | 75 | call_user_func_array([$this->redis, 'rawCommand'], $arguments);
|
| 76 | + $this->throwExceptionIfRawResultIndicatesAnError($rawResult); |
| 77 | + return $rawResult; |
| 78 | + } |
75 | 79 |
|
| 80 | + public function throwExceptionIfRawResultIndicatesAnError($rawResult) |
| 81 | + { |
| 82 | + if (!is_string($rawResult)) { |
| 83 | + return; |
| 84 | + } |
76 | 85 | if ($rawResult === 'Unknown Index name') {
|
77 | 86 | throw new UnknownIndexNameException();
|
78 | 87 | }
|
79 |
| - $unsupportedLanguageMessages = ['Unsupported Language', 'Unsupported Stemmer Language']; |
80 |
| - if (in_array($rawResult, $unsupportedLanguageMessages)) { |
| 88 | + if (in_array($rawResult, ['Unsupported Language', 'Unsupported Stemmer Language'])) { |
81 | 89 | throw new UnsupportedLanguageException();
|
82 | 90 | }
|
83 |
| - |
84 |
| - return $rawResult; |
| 91 | + if (strpos($rawResult, 'ERR unknown command \'FT.') !== false) { |
| 92 | + throw new UnknownRediSearchCommandException($rawResult); |
| 93 | + } |
85 | 94 | }
|
86 | 95 |
|
87 | 96 | public function setLogger(LoggerInterface $logger): RedisClient
|
|
0 commit comments