Loading skill
Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Maps Spring Boot 3 exceptions to RFC 9457 Problem Details responses, preserving any existing legacy error contract.
79% 100%+21 ptsof test cases passed
Passed 24 of 24 test cases with the skill, and 19 of 24 without it.
This test ran on v3. v4 is the current version and hasn’t been tested on gemini-3.6-flash yet.
3 of 3 safety checks passed
Not used yet
package com.example.common.exception;
import jakarta.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ProblemDetail;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
import java.net.URI;
import java.time.Instant;
import java.util.Map;
import java.util.Locale;
@RestControllerAdvice
public class ProblemDetailExceptionHandler extends ResponseEntityExceptionHandler {
private static final Logger log = LoggerFactory.getLogger(ProblemDetailExceptionHandler.class);
private static final String ERROR_BASE_URI = "https://api.example.com/errors/";
@ExceptionHandler(DomainException.class)
public ProblemDetail handleDomainException(DomainException ex, HttpServletRequest request) {
HttpStatus status = ex.getHttpStatus();
ProblemDetail problem = ProblemDetail.forStatusAndDetail(status, ex.getMessage());
problem.setType(URI.create(ERROR_BASE_URI + ex.getErrorCode().toLowerCase(Locale.ROOT)));
problem.setTitle(status.getReasonPhrase());
problem.setInstance(URI.create(request.getRequestURI()));
problem.setProperty("errorCode", ex.getErrorCode());
problem.setProperty("timestamp", Instant.now());
return problem;
}Next to this one in the catalogue, plus more from the same author.