Skip to content

Commit

Permalink
全局回调出错不应该影响业务逻辑回调
Browse files Browse the repository at this point in the history
  • Loading branch information
kiss291323003 committed Nov 6, 2020
1 parent 91f66a8 commit d8f949b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 11 additions & 7 deletions src/RpcClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,17 @@ private function callback(Response $response, ServiceCall $serviceCall)
$globalCall = $this->clientConfig->getOnGlobalFail();
$call = $serviceCall->getOnFail();
}

if (is_callable($globalCall)) {
call_user_func($globalCall, $response, $serviceCall);
}

if (is_callable($call)) {
call_user_func($call, $response, $serviceCall);
//全局回调出错不应该影响业务逻辑回调
try{
if (is_callable($globalCall)) {
call_user_func($globalCall, $response, $serviceCall);
}
}catch (\Throwable $throwable){
throw $throwable;
} finally {
if (is_callable($call)) {
call_user_func($call, $response, $serviceCall);
}
}
}
}
2 changes: 1 addition & 1 deletion src/TcpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function recv(float $timeout = 3.0):Response
}else{
return new Response([
'status'=>Response::STATUS_SERVICE_ERROR,
'message'=>$data
'msg'=>$data
]);
}
}else{
Expand Down

0 comments on commit d8f949b

Please sign in to comment.