refactor: 使用 ApiMessage 统一错误响应格式
- 在多个控制器中引入 ApiMessage,替换原有的 ApiResponse 错误处理逻辑,确保错误信息的一致性与可读性。 - 更新错误返回信息,使用更具语义的键值,提升 API 的可维护性与用户体验。 - 适配相关控制器的请求参数,确保在处理错误时能够正确返回相应的错误信息。
This commit is contained in:
@@ -3,7 +3,9 @@
|
||||
namespace App\Http\Controllers\Api\V1\Admin\Settlement;
|
||||
|
||||
use App\Lottery\ErrorCode;
|
||||
use App\Support\ApiMessage;
|
||||
use App\Support\ApiResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\SettlementBatch;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
@@ -13,18 +15,12 @@ final class AdminSettlementBatchPayoutController extends Controller
|
||||
{
|
||||
public function __construct(private readonly SettlementBatchWorkflowService $service) {}
|
||||
|
||||
public function __invoke(SettlementBatch $batch): JsonResponse
|
||||
public function __invoke(Request $request, SettlementBatch $batch): JsonResponse
|
||||
{
|
||||
try {
|
||||
$updated = $this->service->payout($batch);
|
||||
} catch (\RuntimeException $e) {
|
||||
$reason = $e->getMessage();
|
||||
$msg = match ($reason) {
|
||||
'settlement_not_approved' => trans('api.settlement_not_approved'),
|
||||
default => trans('api.client_error'),
|
||||
};
|
||||
|
||||
return ApiResponse::error($msg, ErrorCode::ClientHttpError->value, ['reason' => $reason], 409);
|
||||
return ApiMessage::runtimeErrorResponse($request, $e);
|
||||
}
|
||||
|
||||
return ApiResponse::success([
|
||||
|
||||
Reference in New Issue
Block a user