From cd7fa3bac296a352667ee03fe9372b9c35a27890 Mon Sep 17 00:00:00 2001 From: OpenClaw Date: Fri, 6 Mar 2026 17:43:24 +0000 Subject: [PATCH] auto(agent): added try/catch and proper HTTP status codes in profile.js --- backend/src/routes/profile.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/backend/src/routes/profile.js b/backend/src/routes/profile.js index caa8dad..6ff1e7b 100644 --- a/backend/src/routes/profile.js +++ b/backend/src/routes/profile.js @@ -7,13 +7,18 @@ import { encryptText } from '../services/encryption.js'; const router = Router(); router.post('/phone', requireAuth, async (req, res) => { - const parsed = z.object({ phone: z.string().min(6).max(40) }).safeParse(req.body); - if (!parsed.success) return res.status(400).json({ error: parsed.error.flatten() }); + try { + const parsed = z.object({ phone: z.string().min(6).max(40) }).safeParse(req.body); + if (!parsed.success) return res.status(400).json({ error: parsed.error.flatten() }); - const encryptedPhone = encryptText(parsed.data.phone); - await pool.query('UPDATE users SET phone_encrypted = ? WHERE id = ?', [encryptedPhone, req.user.userId]); + const encryptedPhone = encryptText(parsed.data.phone); + await pool.query('UPDATE users SET phone_encrypted = ? WHERE id = ?', [encryptedPhone, req.user.userId]); - res.json({ status: 'updated' }); + res.status(200).json({ status: 'updated' }); + } catch (error) { + console.error('Error updating phone:', error); + res.status(500).json({ error: 'Internal server error' }); + } }); -export default router; +export default router; \ No newline at end of file