I got problem with getting proper error message when doing transaction rollback in Phalcon. Little piece of code:
if(!$mailingList->save()){
$this->transaction->rollback("Can't save mailingList model");
return (new IR(false))->setErrors(\Helpers\Response::getErrors($mailingList));
}
I've got my custom class "InternalResponse" aliased as "IR" which gives me all necessary information in debugging process, but when I do a rollback it prevents from returning my message to a higher level. In order to that I can't see what was the problem with saving model. I tried to pass my IR class as rollback parameter and also array containing errors but both approaches don't work, because rollback() accept just String as parameter.
I would appreciate if anyone could give me some clue.
答案 0 :(得分:1)
事务回滚会抛出异常,因此它会绕过该返回语句,因为它将传播到最近的catch块或PHP运行时异常捕获器。
如果您想重新抛出消息或以其他方式处理消息,请执行以下操作:
try {
if (!$mailingList->save()) {
$this->transaction->rollback("Can't save mailingList model");
}
} catch (\Exception $e) {
// $e->getMessage() === "Can't save mailingList model"
return (new IR(false))->setErrors($e->getMessage());
}