Files
Mitgliederverwaltung/.plans/open/issue-212-error-handling-inconsistency.md
T
shahondin1624 b29a268b1d Restructure .plans/ into done/ and open/ subdirectories
- Move completed plan files to .plans/done/
- Move 18 open plan files to .plans/open/
- Update .gitignore to exclude .verified_plans temp file
- Verified all 18 open plans still describe unimplemented issues
2026-04-28 20:30:55 +02:00

2.1 KiB

Issue #212: Inconsistent Error Handling Across Controllers

Problem

Different controllers handle errors differently:

Logging inconsistency:

// Some controllers log errors:
$this->logger->error('Failed to create member', ['exception' => $e, ...]);

// Some controllers don't log at all

Exception handling inconsistency:

// Some controllers catch multiple exception types:
} catch (DoesNotExistException $e) {
    return new JSONResponse(['error' => 'Not found'], 404);
} catch (\Exception $e) {
    return new JSONResponse(['error' => 'Server error'], 500);
}

// Some controllers use generic catches:
} catch (Exception $e) { ... }

Error message language:

return new JSONResponse(['error' => 'Mitglied nicht gefunden'], 404);  // German
return new JSONResponse(['error' => 'Member not found'], 404);          // English

Impact

  • Inconsistent user experience
  • Difficult to debug production issues
  • Potential information leakage (stack traces in logs)
  • Mixed language in API responses

Solution

  1. Create a base controller with standardized error handling:

    abstract class BaseApiController extends ApiController {
        protected function handleNotFound(DoesNotExistException $e): JSONResponse {
            $this->logger->warning('Resource not found', ['exception' => $e]);
            return $this->error('Resource not found', 404);
        }
    
        protected function handleError(\Exception $e, string $action): JSONResponse {
            $this->logger->error("$action failed", ['exception' => $e]);
            return $this->error('An error occurred', 500);
        }
    }
    
  2. Define consistent error messages in one place (enum or constants)

  3. Ensure all controllers extend the base class

Tasks

  • Create BaseApiController with standardized error methods
  • Define ErrorMessages enum with all error strings
  • Update all controllers to extend BaseApiController
  • Ensure consistent logging (all errors logged, exceptions include context)
  • Standardize on German or bilingual error messages
  • Add tests for error handling behavior

Labels

  • bug
  • backend
  • priority:medium