Performance: ResponseEntityExceptionHandler
MEDIUM IMPACT
This affects server response time and client perceived latency by centralizing exception handling and controlling HTTP responses.
@ControllerAdvice public class GlobalExceptionHandler extends ResponseEntityExceptionHandler { @Override protected ResponseEntity<Object> handleExceptionInternal(Exception ex, Object body, HttpHeaders headers, HttpStatus status, WebRequest request) { // custom error response return super.handleExceptionInternal(ex, body, headers, status, request); } }
try { // controller logic } catch (Exception e) { return new ResponseEntity<>("Error", HttpStatus.INTERNAL_SERVER_ERROR); }
| Pattern | Exception Handling Logic | Response Consistency | Server CPU Usage | Verdict |
|---|---|---|---|---|
| Scattered try-catch in controllers | Multiple per controller | Inconsistent | High due to duplication | [X] Bad |
| Centralized ResponseEntityExceptionHandler | Single global handler | Consistent | Lower due to reuse | [OK] Good |