auto(agent): Added error handling to address change request and verification routes

This commit is contained in:
OpenClaw 2026-03-06 17:00:34 +00:00
parent f03b758e18
commit ed38467091

View file

@ -16,6 +16,7 @@ router.post('/change-request', requireAuth, async (req, res) => {
const verificationCode = String(randomInt(100000, 999999));
const verificationCodeHash = hashCode(verificationCode);
try {
const [result] = await pool.query(
`INSERT INTO address_change_requests (user_id, new_address_encrypted, verification_code_hash)
VALUES (?, ?, ?)`,
@ -28,6 +29,10 @@ router.post('/change-request', requireAuth, async (req, res) => {
note: 'Verification code generated for postal letter dispatch.',
verificationCode
});
} catch (err) {
console.error('Error in address change request:', err);
res.status(500).json({ error: 'Internal server error' });
}
});
router.post('/verify', requireAuth, async (req, res) => {
@ -36,6 +41,7 @@ router.post('/verify', requireAuth, async (req, res) => {
const { requestId, code } = parsed.data;
try {
const [rows] = await pool.query(
`SELECT id, user_id, new_address_encrypted, verification_code_hash, status
FROM address_change_requests
@ -72,12 +78,17 @@ router.post('/verify', requireAuth, async (req, res) => {
await conn.commit();
} catch (err) {
await conn.rollback();
console.error('Error in address verification transaction:', err);
throw err;
} finally {
conn.release();
}
res.json({ status: 'verified' });
} catch (err) {
console.error('Error in address verification:', err);
res.status(500).json({ error: 'Internal server error' });
}
});
export default router;