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 3a868f4500
commit 98fe68638c

View File

@@ -263,7 +263,13 @@ class FalukantController {
} catch (error) {
console.error('Controller error:', error);
const status = error.status && typeof error.status === 'number' ? error.status : 500;
res.status(status).json({ error: error.message || 'Internal error' });
// 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' });
}
}
};
}