Skip to content

one_d4: replace generic Exception catch-all with Micronaut native error handling #1052

@aaylward

Description

@aaylward

Problem

ErrorHandler has a catch-all @Error(global = true, exception = Exception.class) handler that intercepts all exceptions before Micronaut's built-in handlers can run. This means framework-level HTTP exceptions (415, 405, 406, etc.) that Micronaut would handle correctly by default instead fall through to the catch-all and return 500.

We already hit this once with UnsupportedMediaException (fixed in #1051 by adding an explicit handler), but any future framework exception will have the same problem until explicitly listed.

Proposed fix

Remove handleGeneric and rely on Micronaut's built-in exception handlers, which return correct HTTP status codes for framework-level errors. To avoid leaking exception details in 500 responses (the reason the catch-all was added), configure Micronaut/Jackson to suppress exception messages from error response bodies.

Keep the application-specific handlers (ParseException → 400, IllegalArgumentException → 400, NoSuchElementException → 404) since those are not covered by Micronaut defaults.

Expected outcome

  • Framework exceptions (wrong Content-Type, wrong method, not acceptable, etc.) get correct 4xx status codes without needing explicit handlers
  • Unhandled exceptions still return 500 without leaking stack traces or internal messages
  • No more whack-a-mole adding handlers for exceptions Micronaut already knows about

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions