From 977545344298d7f6d65efc0e340e50787d903061 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=A4=80=ED=9D=A0?= Date: Tue, 3 Mar 2026 09:07:03 +0900 Subject: [PATCH] dbmsv4 init...5 --- app/Services/CommonService.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/Services/CommonService.php b/app/Services/CommonService.php index c1de3e8..1bb00d9 100644 --- a/app/Services/CommonService.php +++ b/app/Services/CommonService.php @@ -34,11 +34,18 @@ abstract class CommonService final protected function dbTransaction(callable $callback, string $functionName = ''): mixed { $db = \Config\Database::connect(); + try { $db->transException(true)->transStart(); $result = $callback($db); $db->transComplete(); return $result; + + } catch (FormValidationException $e) { + // ✅ 검증 에러는 감싸지 말고 그대로 던져야 Ajax가 422 + errors 받음 + $db->transRollback(); + throw $e; + } catch (DatabaseException $e) { $errorMessage = sprintf( "\n----[%s]에서 트랜잭션 실패: DB 오류----\n%s\n%s\n------------------------------\n", @@ -48,8 +55,10 @@ abstract class CommonService ); log_message('error', $errorMessage); throw new RuntimeException($errorMessage, $e->getCode(), $e); + } catch (\Throwable $e) { $db->transRollback(); + // ✅ 여기서 FormValidationException까지 RuntimeException으로 바뀌던게 문제였음 throw new RuntimeException($e->getMessage(), $e->getCode(), $e); } }