File tree 2 files changed +38
-13
lines changed
2 files changed +38
-13
lines changed Original file line number Diff line number Diff line change 10
10
11
11
namespace Pulsar \Lookup ;
12
12
13
-
13
+ use Protobuf \ AbstractMessage ;
14
14
use Pulsar \Exception \IOException ;
15
15
use Pulsar \Exception \OptionsException ;
16
16
use Pulsar \Exception \RuntimeException ;
@@ -124,7 +124,7 @@ public function lookup(string $topic): Result
124
124
125
125
//
126
126
default :
127
- throw new RuntimeException ( $ subCommand -> getMessage () );
127
+ $ this -> handleCommandFailed ( $ subCommand );
128
128
}
129
129
}
130
130
@@ -152,7 +152,7 @@ public function getPartitionedTopicMetadata(string $topic): int
152
152
*/
153
153
$ subCommand = $ results ->subCommand ;
154
154
if ($ subCommand ->getResponse ()->value () == CommandPartitionedTopicMetadataResponse \LookupType::Failed_VALUE) {
155
- throw new RuntimeException ( $ subCommand -> getMessage () );
155
+ $ this -> handleCommandFailed ( $ subCommand );
156
156
}
157
157
158
158
return $ subCommand ->getPartitions ();
@@ -214,4 +214,20 @@ public function close()
214
214
{
215
215
$ this ->connection ->close ();
216
216
}
217
- }
217
+
218
+ /**
219
+ * @return void
220
+ * @throws RuntimeException
221
+ */
222
+ protected function handleCommandFailed (AbstractMessage $ command )
223
+ {
224
+ $ code = 0 ;
225
+ $ msg = $ command ->getMessage ();
226
+ if ($ command ->hasError ()) {
227
+ $ code = $ command ->getError ()->value ();
228
+ $ msg = $ command ->getError ()->name ();
229
+ }
230
+
231
+ throw RuntimeException ($ msg , $ code );
232
+ }
233
+ }
Original file line number Diff line number Diff line change @@ -110,10 +110,7 @@ public function getSubCommand(): AbstractMessage
110
110
protected function checkError ()
111
111
{
112
112
if ($ this ->subCommand instanceof CommandError) {
113
- throw new RuntimeException (
114
- $ this ->subCommand ->getMessage (),
115
- $ this ->subCommand ->getError ()->value ()
116
- );
113
+ $ this ->handleSubCommandError ();
117
114
}
118
115
119
116
$ this ->checkServerError ();
@@ -127,10 +124,22 @@ protected function checkError()
127
124
protected function checkServerError ()
128
125
{
129
126
if ($ this ->subCommand instanceof CommandSendError) {
130
- throw new RuntimeException (
131
- $ this ->subCommand ->getMessage (),
132
- $ this ->subCommand ->getError ()->value ()
133
- );
127
+ $ this ->handleSubCommandError ();
134
128
}
135
129
}
136
- }
130
+
131
+ /**
132
+ * @return void
133
+ * @throws RuntimeException
134
+ */
135
+ protected function handleSubCommandError ()
136
+ {
137
+ $ code = 0 ;
138
+ $ msg = $ this ->subCommand ->getMessage ();
139
+ if ($ this ->subCommand ->hasError ()) {
140
+ $ code = $ this ->subCommand ->getError ()->value ();
141
+ $ msg = $ msg ?: $ this ->subCommand ->getError ()->name ();
142
+ }
143
+ throw new RuntimeException ($ msg , $ code );
144
+ }
145
+ }
You can’t perform that action at this time.
0 commit comments