refactor: 规范Expection处理

This commit is contained in:
xboard
2023-12-04 20:40:49 +08:00
parent aa0fe64afe
commit 0ab7dee52d
65 changed files with 625 additions and 362 deletions
+6 -5
View File
@@ -5,6 +5,7 @@
*/
namespace App\Payments;
use App\Exceptions\ApiException;
use \Curl\Curl;
class MGate {
@@ -62,21 +63,21 @@ class MGate {
$curl->post($this->config['mgate_url'] . '/v1/gateway/fetch', http_build_query($params));
$result = $curl->response;
if (!$result) {
abort(500, '网络异常');
throw new ApiException(500, '网络异常');
}
if ($curl->error) {
if (isset($result->errors)) {
$errors = (array)$result->errors;
abort(500, $errors[array_keys($errors)[0]][0]);
throw new ApiException(500, $errors[array_keys($errors)[0]][0]);
}
if (isset($result->message)) {
abort(500, $result->message);
throw new ApiException(500, $result->message);
}
abort(500, '未知错误');
throw new ApiException(500, '未知错误');
}
$curl->close();
if (!isset($result->data->trade_no)) {
abort(500, '接口请求失败');
throw new ApiException(500, '接口请求失败');
}
return [
'type' => 1, // 0:qrcode 1:url