Add global error handling middleware for API routes and enhance rating update logic
Implemented a global error handling middleware in the server to standardize error responses for API routes. Additionally, updated the AutoUpdateRatingsService to retrieve the approved user club before updating ratings, ensuring proper access control. Modified the error handling in MyTischtennisAccount.vue to provide more informative login failure messages.
This commit is contained in:
@@ -71,6 +71,31 @@ process.on('unhandledRejection', (reason, promise) => {
|
||||
console.error('[unhandledRejection]', reason);
|
||||
});
|
||||
|
||||
// Globale Fehlerbehandlung für API-Routen
|
||||
app.use((err, req, res, next) => {
|
||||
if (res.headersSent) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
const status = err?.statusCode || err?.status || 500;
|
||||
const message = err?.message || 'Interner Serverfehler';
|
||||
|
||||
const response = {
|
||||
success: false,
|
||||
message,
|
||||
error: message
|
||||
};
|
||||
|
||||
if (process.env.NODE_ENV === 'dev' || process.env.NODE_ENV === 'development') {
|
||||
response.debug = {
|
||||
stack: err?.stack || null
|
||||
};
|
||||
}
|
||||
|
||||
console.error('[ExpressError]', err);
|
||||
res.status(status).json(response);
|
||||
});
|
||||
|
||||
app.use('/api/auth', authRoutes);
|
||||
app.use('/api/clubs', clubRoutes);
|
||||
app.use('/api/clubmembers', memberRoutes);
|
||||
|
||||
Reference in New Issue
Block a user