Summary
`ErrorHandlerMiddleware` and `StatusCodeMiddleware` both catch exceptions globally, but are nested such that one is effectively dead code, and their response shapes differ.
Details
Pipeline order in `Program.cs:221-226`: `ErrorHandlerMiddleware` wraps `LibraryConfigurationMiddleware` which wraps `StatusCodeMiddleware` which wraps the controllers. `StatusCodeMiddleware`'s catch-all (`catch (Exception ex)`) swallows everything from the controller layer down without rethrowing, so `ErrorHandlerMiddleware` only ever sees exceptions thrown in `LibraryConfigurationMiddleware` itself (or above it).
Response shape also differs between the two:
- `ErrorHandlerMiddleware`: JSON body `{ "message": ... }`
- `StatusCodeMiddleware`: empty body for most statuses, plain text for `BadRequestException`
Impact
Confusing/inconsistent error responses depending on exactly where an exception originates, and one middleware is largely redundant.
Suggested fix
Consolidate into a single exception-handling middleware with one consistent response contract — ideally `application/problem+json` (see #15). Also relevant to fixing #6 (exception message leakage) cleanly.
Summary
`ErrorHandlerMiddleware` and `StatusCodeMiddleware` both catch exceptions globally, but are nested such that one is effectively dead code, and their response shapes differ.
Details
Pipeline order in `Program.cs:221-226`: `ErrorHandlerMiddleware` wraps `LibraryConfigurationMiddleware` which wraps `StatusCodeMiddleware` which wraps the controllers. `StatusCodeMiddleware`'s catch-all (`catch (Exception ex)`) swallows everything from the controller layer down without rethrowing, so `ErrorHandlerMiddleware` only ever sees exceptions thrown in `LibraryConfigurationMiddleware` itself (or above it).
Response shape also differs between the two:
Impact
Confusing/inconsistent error responses depending on exactly where an exception originates, and one middleware is largely redundant.
Suggested fix
Consolidate into a single exception-handling middleware with one consistent response contract — ideally `application/problem+json` (see #15). Also relevant to fixing #6 (exception message leakage) cleanly.