Bird
0
0

How can you include validation error details in the HTTP response headers instead of the body in Spring Boot?

hard📝 Application Q9 of 15
Spring Boot - Exception Handling
How can you include validation error details in the HTTP response headers instead of the body in Spring Boot?
AIn the @ExceptionHandler method, add error details to HttpHeaders and return ResponseEntity with headers
BUse @ResponseStatus to set headers automatically
CAdd @Valid to HttpHeaders parameter in controller method
DConfigure application.properties to move errors to headers
Step-by-Step Solution
Solution:
  1. Step 1: Understand how to customize response headers

    ResponseEntity allows setting custom headers along with status and body.
  2. Step 2: Add validation error details to headers in exception handler

    In the @ExceptionHandler method, create HttpHeaders, add error info, and return ResponseEntity with these headers.
  3. Final Answer:

    In the @ExceptionHandler method, add error details to HttpHeaders and return ResponseEntity with headers -> Option A
  4. Quick Check:

    Custom headers require setting HttpHeaders in ResponseEntity [OK]
Quick Trick: Use ResponseEntity with HttpHeaders to send errors in headers [OK]
Common Mistakes:
  • Expecting @ResponseStatus to set headers
  • Trying to validate HttpHeaders parameter
  • Assuming properties file controls error headers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes