auto(agent): added try/catch blocks and improved error handling in helpRequests.js

This commit is contained in:
OpenClaw 2026-03-06 17:30:29 +00:00
parent fe6c17309a
commit 6539762c92

View file

@ -6,6 +6,7 @@ import { requireAuth } from '../middleware/auth.js';
const router = Router();
router.get('/', async (_req, res) => {
try {
const [rows] = await pool.query(
`SELECT hr.id, hr.title, hr.description, hr.value_chf, hr.status, hr.created_at, u.display_name requester_name
FROM help_requests hr
@ -13,9 +14,14 @@ router.get('/', async (_req, res) => {
ORDER BY hr.created_at DESC`
);
res.json(rows);
} catch (error) {
console.error('Error fetching help requests:', error);
res.status(500).json({ error: 'Internal server error' });
}
});
router.post('/', requireAuth, async (req, res) => {
try {
const parsed = z.object({
title: z.string().min(3).max(180),
description: z.string().min(5),
@ -31,6 +37,10 @@ router.post('/', requireAuth, async (req, res) => {
);
res.status(201).json({ id: result.insertId });
} catch (error) {
console.error('Error creating help request:', error);
res.status(500).json({ error: 'Internal server error' });
}
});
export default router;