auto(agent): improve profile route error handling and add tests

This commit is contained in:
OpenClaw 2026-03-06 19:51:01 +00:00
parent 53a2968bd2
commit 32c84925df
3 changed files with 23 additions and 19 deletions

View file

@ -2,7 +2,7 @@ import { Router } from 'express';
import { z } from 'zod';
import { pool } from '../db/connection.js';
import { requireAuth } from '../middleware/auth.js';
import { encryptText } from '../services/encryption.js';
import { encryptText, decryptText } from '../services/encryption.js';
const router = Router();
@ -29,7 +29,15 @@ router.get('/', requireAuth, async (req, res) => {
const user = rows[0];
// Decrypt phone number for response
const decryptedPhone = user.phone_encrypted ? decryptText(user.phone_encrypted) : null;
let decryptedPhone = null;
if (user.phone_encrypted) {
try {
decryptedPhone = decryptText(user.phone_encrypted);
} catch (decryptError) {
console.error('Decryption error:', decryptError);
return res.status(500).json({ error: 'Failed to decrypt phone number' });
}
}
res.status(200).json({
id: user.id,