Commit dc221dc7 authored by 杨培's avatar 杨培

优化了 Server 端的异常机制

parent ee8b1cbc
......@@ -18,4 +18,32 @@ namespace internalApi\base;
*/
class ApiException extends \Exception
{
protected $remote;
public function __construct($message = "", $code = 0, array $remote=null, \Throwable $previous = NULL) {
parent::__construct($message, $code, $previous);
$this->remote = $remote;
}
public function getRemoteClass()
{
return $this->remote['class'];
}
public function getRemoteLine()
{
return $this->remote['line'];
}
public function getRemoteFile()
{
return $this->remote['file'];
}
public function getRemoteTraceString()
{
return $this->remote['traceString'];
}
}
\ No newline at end of file
......@@ -125,7 +125,7 @@ class Client
if ($httpCode == 500 && substr($response, 0, 10) === 'exception:') {
$e = substr($response, 10);
$e = json_decode($e, true);
throw new ApiException("{$e['class']}: {$e['message']}", $e['code']);
throw new ApiException($e['message'], $e['code'], $e);
}
if ($httpCode == 0) {
......
......@@ -118,7 +118,7 @@ class Server
'class' => get_class($e),
'code' => $e->getCode(),
'message' => $e->getMessage(),
'line' => $e->getFile(),
'line' => $e->getLine(),
'file' => $e->getFile(),
'traceString' => $e->getTraceAsString()
];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment