auto(agent): Added error handling to address change request and verification routes
This commit is contained in:
parent
f03b758e18
commit
ed38467091
1 changed files with 58 additions and 47 deletions
|
|
@ -16,6 +16,7 @@ router.post('/change-request', requireAuth, async (req, res) => {
|
||||||
const verificationCode = String(randomInt(100000, 999999));
|
const verificationCode = String(randomInt(100000, 999999));
|
||||||
const verificationCodeHash = hashCode(verificationCode);
|
const verificationCodeHash = hashCode(verificationCode);
|
||||||
|
|
||||||
|
try {
|
||||||
const [result] = await pool.query(
|
const [result] = await pool.query(
|
||||||
`INSERT INTO address_change_requests (user_id, new_address_encrypted, verification_code_hash)
|
`INSERT INTO address_change_requests (user_id, new_address_encrypted, verification_code_hash)
|
||||||
VALUES (?, ?, ?)`,
|
VALUES (?, ?, ?)`,
|
||||||
|
|
@ -28,6 +29,10 @@ router.post('/change-request', requireAuth, async (req, res) => {
|
||||||
note: 'Verification code generated for postal letter dispatch.',
|
note: 'Verification code generated for postal letter dispatch.',
|
||||||
verificationCode
|
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) => {
|
router.post('/verify', requireAuth, async (req, res) => {
|
||||||
|
|
@ -36,6 +41,7 @@ router.post('/verify', requireAuth, async (req, res) => {
|
||||||
|
|
||||||
const { requestId, code } = parsed.data;
|
const { requestId, code } = parsed.data;
|
||||||
|
|
||||||
|
try {
|
||||||
const [rows] = await pool.query(
|
const [rows] = await pool.query(
|
||||||
`SELECT id, user_id, new_address_encrypted, verification_code_hash, status
|
`SELECT id, user_id, new_address_encrypted, verification_code_hash, status
|
||||||
FROM address_change_requests
|
FROM address_change_requests
|
||||||
|
|
@ -72,12 +78,17 @@ router.post('/verify', requireAuth, async (req, res) => {
|
||||||
await conn.commit();
|
await conn.commit();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
await conn.rollback();
|
await conn.rollback();
|
||||||
|
console.error('Error in address verification transaction:', err);
|
||||||
throw err;
|
throw err;
|
||||||
} finally {
|
} finally {
|
||||||
conn.release();
|
conn.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
res.json({ status: 'verified' });
|
res.json({ status: 'verified' });
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error in address verification:', err);
|
||||||
|
res.status(500).json({ error: 'Internal server error' });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue