From 08b6437a1eb6b9adecb6fbcff053d483ce6f9a2e Mon Sep 17 00:00:00 2001 From: "Torsten Schulz (local)" Date: Wed, 28 Jan 2026 13:29:15 +0100 Subject: [PATCH] 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. --- backend/controllers/falukantController.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/backend/controllers/falukantController.js b/backend/controllers/falukantController.js index e7db3d4..d1df872 100644 --- a/backend/controllers/falukantController.js +++ b/backend/controllers/falukantController.js @@ -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' }); + } } }; }