@@ -11,11 +11,19 @@ abstract protected function getServiceName(): string;
11
11
* @return string
12
12
*/
13
13
abstract protected function getMethodName (): string ;
14
- public function setParameters ($ parameters ): Client {
15
- if (! is_array ($ parameters ) && ! is_object ($ parameters )) {
16
- throw new \Exception ('Only accept array or object ' );
14
+ public function setParameters (array |object $ parameters ): Client {
15
+ $ this ->parameters = (array )$ parameters ;
16
+ return $ this ;
17
+ }
18
+ public function withParameter (string $ key , mixed $ parameter ): Client {
19
+ $ this ->parameters ??= [];
20
+ $ this ->parameters [$ key ] = $ parameter ;
21
+ return $ this ;
22
+ }
23
+ public function withoutParameter (string $ key ): Client {
24
+ if (isset ($ this ->parameters ) && isset ($ this ->parameters [$ key ])) {
25
+ unset($ this ->parameters [$ key ]);
17
26
}
18
- $ this ->parameters = $ parameters ;
19
27
return $ this ;
20
28
}
21
29
protected function getExceptionName (): array {
@@ -82,12 +90,7 @@ public function getResult(): ?object {
82
90
}
83
91
$ response = $ this ->recv ();
84
92
if (503 === $ response ->statusCode ) {
85
- try {
86
- \Swango \Aliyun \Slb \Scene \FindServerByServerName::find ($ this ->getServiceName ());
87
- throw new Client \Exception \ApiErrorException (static ::class . ' api code error :503 ' );
88
- } catch (\Swango \Aliyun \Slb \Exception \ServerNotAvailableException $ e ) {
89
- throw new Client \Exception \ServerClosedException ();
90
- }
93
+ throw new Client \Exception \ServerClosedException ();
91
94
}
92
95
$ result_object = \Json::decodeAsObject ($ response ->body );
93
96
if (! isset ($ result_object ->code ) || ! isset ($ result_object ->enmsg ) || ! isset ($ result_object ->cnmsg )) {
@@ -97,7 +100,11 @@ public function getResult(): ?object {
97
100
throw new Client \Exception \ApiErrorException ('Invalid response format ' );
98
101
}
99
102
if (200 !== $ result_object ->code || 'ok ' !== $ result_object ->enmsg ) {
100
- throw new Client \Exception \ApiErrorException ("[ $ result_object ->code ] $ result_object ->enmsg $ result_object ->cnmsg " );
103
+ if (Environment::getSwangoModuleSeeker ()->swangoModelExists ()) {
104
+ throw new \ExceptionToResponse ($ result_object ->enmsg , $ result_object ->cnmsg , $ result_object ->code );
105
+ } else {
106
+ throw new Client \Exception \ApiErrorException ("[ $ result_object ->code ] $ result_object ->enmsg $ result_object ->cnmsg " );
107
+ }
101
108
}
102
109
return $ result_object ->data ?? null ;
103
110
}
0 commit comments