fix: company save 500 error — catch DB exceptions, show error to user
- CompanyRepository::save() now catches PDOException and throws a RuntimeException with a human-readable message (duplicate name, etc.) - Also fixes unchecked checkboxes (requires_approval, is_active) not being saved as 0 on UPDATE - index.php save handler catches RuntimeException and redirects back to the form with an ?error= param instead of crashing with 500 - companyEdit() renders the error banner when ?error= is present Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
68317da748
commit
b25126e52b
@@ -1017,7 +1017,12 @@ HTML;
|
||||
$botOptions .= "<option value=\"{$val}\" {$sel}>{$lbl}</option>\n";
|
||||
}
|
||||
|
||||
$pageTitle = $isEdit ? 'Editar Empresa' : 'Nueva Empresa';
|
||||
$pageTitle = $isEdit ? 'Editar Empresa' : 'Nueva Empresa';
|
||||
$errorBanner = '';
|
||||
if (!empty($_GET['error'])) {
|
||||
$errText = self::h(urldecode($_GET['error']));
|
||||
$errorBanner = "<div style='background:#fef2f2;border:1px solid #fca5a5;color:#991b1b;padding:12px 16px;border-radius:8px;margin-bottom:16px;font-size:14px'>⚠ {$errText}</div>";
|
||||
}
|
||||
echo Layout::open($pageTitle, 'companies', $user['name'] ?? 'Admin');
|
||||
|
||||
// ── Tab: Números WhatsApp ─────────────────────────────────────────────
|
||||
@@ -1251,6 +1256,7 @@ HTML : '';
|
||||
<h1 style="font-size:18px;font-weight:700;color:#111827">{$pageTitle}</h1>
|
||||
<a href="/admin/companies" class="btn-secondary" style="font-size:12px">← Empresas</a>
|
||||
</div>
|
||||
{$errorBanner}
|
||||
{$tabsHtml}
|
||||
|
||||
<!-- Tab General -->
|
||||
|
||||
Reference in New Issue
Block a user