Scrivio Interview library

Error handling

25 questions in 7 subtopics.

@ExceptionHandler

CodingFoundations5 min read
Write an @ExceptionHandler that maps OrderNotFoundException to 404 with a JSON body, inside a controller.
InternalsIntermediate6 min read
In what order does Spring MVC try to handle an exception from a controller, and what happens if nothing handles it?
LeadershipPrincipal6 min read
How do you build an organisation-wide culture where errors are handled consistently and are useful for operations, not only for API clients?
LeadershipPrincipal6 min read
How would you balance exposing detailed error information to help clients against the security risk of leaking internals, as a company-wide policy?

@ControllerAdvice

ConceptFoundations5 min read
What is @RestControllerAdvice, and how do you limit it to certain controllers?
DebuggingIntermediate5 min read
Two @RestControllerAdvice classes exist: one in a shared library handling Exception and one in the service handling OrderNotFoundException. Sometimes the library's generic 500 response is returned for OrderNotFoundException. Why?
ScenarioIntermediate6 min read
An exception thrown in a servlet filter returns an HTML or default JSON error instead of your @ControllerAdvice format. Why, and how do you make it consistent?
DesignAdvanced6 min read
Design a shared error-handling starter for all services. What would it contain and how would teams extend it?

ProblemDetail

ConceptFoundations6 min read
What is ProblemDetail in Spring Framework 6, which standard does it follow, and how do you enable it in Spring Boot?
CodingFoundations5 min read
Return a ProblemDetail with status 409, a type URI and a custom property orderId from an @ExceptionHandler.
DesignIntermediate6 min read
Your advice extends ResponseEntityExceptionHandler. What does that give you, and what would you customise?
ScenarioAdvanced5 min read
Your API gateway, Spring Security and services all produce error responses in different formats. Clients see three error shapes for one API. How would you unify them?

Error responses design

DebuggingFoundations6 min read
In production, error responses suddenly contain stack traces. Which properties control this in Spring Boot?
DesignIntermediate6 min read
Design the error response format for a public API. What fields would you include and what would you never include?
LeadershipAdvanced5 min read
Error formats differ across 80 services, which makes client and gateway code complex. How would you create a common error contract and migrate to it?
LeadershipPrincipal6 min read
Error contracts outlive the services that produce them. How would you govern error codes across a company for many years so that clients can rely on them?

Handling validation errors

CodingFoundations5 min read
Return a 400 response listing each invalid field and its message when @Valid @RequestBody fails.
CodingIntermediate8 min read
Handle HandlerMethodValidationException from Spring 6.1 method validation and return field errors for parameters.
DesignAdvanced8 min read
Clients complain that validation error messages change wording in every release and break their parsing. What contract would you define?
LeadershipPrincipal7 min read
Validation and business errors are often reported as 500 in older services, which hides real failures in dashboards. How would you change this across the company and measure the effect?

Handler exception resolvers

InternalsFoundations6 min read
Which HandlerExceptionResolver implementations does Spring MVC register by default, in what order, and what does each handle?
DebuggingIntermediate7 min read
A custom HandlerExceptionResolver that logs and returns JSON for all exceptions was added as a bean, but @ExceptionHandler methods in @ControllerAdvice stopped being called for some exceptions, while for others your resolver never runs. Explain the ordering and fix.
DesignAdvanced6 min read
Your services are split between Spring MVC and WebFlux, and the error handling mechanisms differ. How would you design a consistent error handling library for both stacks?

Whitelabel and custom error pages

ConceptFoundations7 min read
What is Spring Boot's Whitelabel Error Page, which component produces it, and how do you replace it with custom HTML pages per status code?
DebuggingIntermediate7 min read
A secured Spring Boot app shows a login page or a 401 instead of the custom 404 page for unknown URLs, and the logs show access denied for /error. Why, and how do you fix it?