Improve error handling in FalukantController: Enhance response structure for error objects by including additional error data while maintaining status code integrity. This change allows for more informative error messages in the API response.

This commit is contained in:
Torsten Schulz (local)
2026-01-28 13:29:15 +01:00
parent baffd9d05c
commit 08b6437a1e

View File

@@ -263,8 +263,14 @@ class FalukantController {
} catch (error) { } catch (error) {
console.error('Controller error:', error); console.error('Controller error:', error);
const status = error.status && typeof error.status === 'number' ? error.status : 500; const status = error.status && typeof error.status === 'number' ? error.status : 500;
// Wenn error ein Objekt mit status ist, alle Felder außer status übernehmen
if (error && typeof error === 'object' && error.status && typeof error.status === 'number') {
const { status: errorStatus, ...errorData } = error;
res.status(errorStatus).json({ error: error.message || errorData.message || 'Internal error', ...errorData });
} else {
res.status(status).json({ error: error.message || 'Internal error' }); res.status(status).json({ error: error.message || 'Internal error' });
} }
}
}; };
} }