You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[REFACTOR] Enforce consistent HTTP status code management in exception handlers #220
In the current GlobalExceptionHandler.java, exception handlers are configured with redundant and potentially conflicting annotations. For example, handleNotFoundException has:
In Spring Framework, when a handler returns a ResponseEntity, it completely overrides any @ResponseStatus class-level or method-level annotations. Thus, @ResponseStatus(HttpStatus.NOT_FOUND) is dead code. Furthermore, defining status codes in multiple places invites configuration slip where a developer changes the ResponseEntity status but forgets to update the @ResponseStatus annotation, making the code confusing.
Proposed Solution
Perform a code clean-up on GlobalExceptionHandler.java. Remove all @ResponseStatus annotations from methods that return ResponseEntity. Enforce a rule that all HTTP status code configurations are declared in a single location—ideally directly within the ResponseEntity.status(...) factory call.
User Stories
As a backend developer, I want exception handlers to define response codes in a single, consistent way so that the code is readable and free of redundant configuration.
Acceptance Criteria
All @ResponseStatus annotations are removed from methods returning ResponseEntity inside GlobalExceptionHandler.java.
All custom controller files are audited to ensure they do not mix @ResponseStatus annotations on endpoints that return ResponseEntity.
Status codes are configured solely through the return expression.
Tasks
Audit GlobalExceptionHandler.java and remove @ResponseStatus on lines 55, 64, 73, 83, 93, 102, 111, 121, 130, 139, 154, 163, 178, and 187.
Confirm application behavior during exception handling remains identical.
Activity