feat: 增强风险池 Redis 操作,添加 TTL 支持并更新相关 Lua 脚本;新增 API 异常响应测试
This commit is contained in:
@@ -13,6 +13,7 @@ use App\Lottery\ErrorCode;
|
||||
use App\Support\ApiResponse;
|
||||
use App\Support\ApiValidationErrors;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Support\LotteryLocale;
|
||||
use Illuminate\Foundation\Application;
|
||||
use App\Http\Middleware\EnsureAdminApi;
|
||||
@@ -174,13 +175,40 @@ return Application::configure(basePath: dirname(__DIR__))
|
||||
return null;
|
||||
}
|
||||
|
||||
$showDetails = (bool) config('app.debug');
|
||||
$showDetails = (bool) config('app.debug')
|
||||
|| (bool) env('API_ERROR_DETAILS', false)
|
||||
|| app()->environment(['local', 'testing']);
|
||||
$errorId = (string) Str::uuid();
|
||||
report($e);
|
||||
|
||||
$msg = $showDetails ? $e->getMessage() : trans('api.server_error', [], $locale($request));
|
||||
$details = [
|
||||
'error_id' => $errorId,
|
||||
];
|
||||
|
||||
if ($showDetails) {
|
||||
$details['exception'] = $e::class;
|
||||
$details['message'] = $e->getMessage();
|
||||
$details['file'] = $e->getFile();
|
||||
$details['line'] = $e->getLine();
|
||||
$details['trace'] = collect($e->getTrace())
|
||||
->take(10)
|
||||
->map(static function (array $frame): array {
|
||||
return [
|
||||
'file' => $frame['file'] ?? null,
|
||||
'line' => $frame['line'] ?? null,
|
||||
'class' => $frame['class'] ?? null,
|
||||
'function' => $frame['function'] ?? null,
|
||||
];
|
||||
})
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
|
||||
return ApiResponse::error(
|
||||
$msg !== '' ? $msg : trans('api.server_error', [], $locale($request)),
|
||||
ErrorCode::InternalError->value,
|
||||
$showDetails ? ['exception' => $e::class] : null,
|
||||
$details,
|
||||
500,
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user