dbmsv4 init...5
This commit is contained in:
parent
7fb1408259
commit
9775453442
@ -34,11 +34,18 @@ abstract class CommonService
|
|||||||
final protected function dbTransaction(callable $callback, string $functionName = ''): mixed
|
final protected function dbTransaction(callable $callback, string $functionName = ''): mixed
|
||||||
{
|
{
|
||||||
$db = \Config\Database::connect();
|
$db = \Config\Database::connect();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$db->transException(true)->transStart();
|
$db->transException(true)->transStart();
|
||||||
$result = $callback($db);
|
$result = $callback($db);
|
||||||
$db->transComplete();
|
$db->transComplete();
|
||||||
return $result;
|
return $result;
|
||||||
|
|
||||||
|
} catch (FormValidationException $e) {
|
||||||
|
// ✅ 검증 에러는 감싸지 말고 그대로 던져야 Ajax가 422 + errors 받음
|
||||||
|
$db->transRollback();
|
||||||
|
throw $e;
|
||||||
|
|
||||||
} catch (DatabaseException $e) {
|
} catch (DatabaseException $e) {
|
||||||
$errorMessage = sprintf(
|
$errorMessage = sprintf(
|
||||||
"\n----[%s]에서 트랜잭션 실패: DB 오류----\n%s\n%s\n------------------------------\n",
|
"\n----[%s]에서 트랜잭션 실패: DB 오류----\n%s\n%s\n------------------------------\n",
|
||||||
@ -48,8 +55,10 @@ abstract class CommonService
|
|||||||
);
|
);
|
||||||
log_message('error', $errorMessage);
|
log_message('error', $errorMessage);
|
||||||
throw new RuntimeException($errorMessage, $e->getCode(), $e);
|
throw new RuntimeException($errorMessage, $e->getCode(), $e);
|
||||||
|
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
$db->transRollback();
|
$db->transRollback();
|
||||||
|
// ✅ 여기서 FormValidationException까지 RuntimeException으로 바뀌던게 문제였음
|
||||||
throw new RuntimeException($e->getMessage(), $e->getCode(), $e);
|
throw new RuntimeException($e->getMessage(), $e->getCode(), $e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user