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

View File

@@ -2,6 +2,7 @@
namespace App\Http\Controllers\V1\Guest;
use App\Exceptions\ApiException;
use App\Http\Controllers\Controller;
use App\Models\Order;
use App\Services\OrderService;
@@ -16,13 +17,13 @@ class PaymentController extends Controller
try {
$paymentService = new PaymentService($method, null, $uuid);
$verify = $paymentService->notify($request->input());
if (!$verify) abort(500, 'verify error');
if (!$verify) throw new ApiException(500, 'verify error');
if (!$this->handle($verify['trade_no'], $verify['callback_no'])) {
abort(500, 'handle error');
throw new ApiException(500, 'handle error');
}
return(isset($verify['custom_result']) ? $verify['custom_result'] : 'success');
} catch (\Exception $e) {
abort(500, 'fail');
throw new ApiException(500, 'fail');
}
}
@@ -30,7 +31,7 @@ class PaymentController extends Controller
{
$order = Order::where('trade_no', $tradeNo)->first();
if (!$order) {
abort(500, 'order is not found');
throw new ApiException(500, 'order is not found');
}
if ($order->status !== 0) return true;
$orderService = new OrderService($order);

View File

@@ -2,6 +2,7 @@
namespace App\Http\Controllers\V1\Guest;
use App\Exceptions\ApiException;
use App\Http\Controllers\Controller;
use App\Services\TelegramService;
use Illuminate\Http\Request;
@@ -15,7 +16,7 @@ class TelegramController extends Controller
public function __construct(Request $request)
{
if ($request->input('access_token') !== md5(admin_setting('telegram_bot_token'))) {
abort(401);
throw new ApiException(401);
}
$this->telegramService = new TelegramService();