How afghaleek/problem-mapper-spring-boot-starter works
Purpose and Integration
This repository is a Java 17 / Spring Boot 3.x starter that converts application exceptions into RFC-style Spring ProblemDetail HTTP responses. It is a library, not a standalone application: Spring Boot discovers and activates it through src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports.
The consumer-facing entry point is the @ResponseError annotation at src/main/java/io/github/daoud/problemapper/annotation/ResponseError.java, applied to exception classes.
Auto-Configuration Boundary
src/main/java/io/github/daoud/problemapper/autoconfigure/ProblemMapperAutoConfiguration.java is the composition root. It registers the starter’s runtime beans when present on a consuming Spring Boot application's classpath and binds configurable behavior through src/main/java/io/github/daoud/problemapper/properties/ProblemMapperProperties.java.
This is the principal boundary between consumer application code and the starter: applications supply exceptions, configuration properties, and HTTP requests; the starter supplies exception translation.
Exception Metadata Stage
src/main/java/io/github/daoud/problemapper/annotation/ResponseError.java declares static response metadata on exception types: HTTP status, application error code, and default message.
At runtime, the mapper inspects the thrown exception’s class for this annotation. The exception instance message can provide dynamic detail, while the annotation provides a stable API-level error classification.
Global HTTP Exception Interception
src/main/java/io/github/daoud/problemapper/handler/ResponseErrorExceptionHandler.java is the global Spring MVC exception-handling layer. It receives exceptions escaping REST controller execution, determines whether they carry @ResponseError, and delegates response construction.
It also provides the fallback path for unannotated or otherwise unmapped exceptions, preventing callers from needing their own repetitive @ControllerAdvice mappings.
ProblemDetail Construction
src/main/java/io/github/daoud/problemapper/factory/ProblemDetailFactory.java centralizes creation of Spring’s ProblemDetail response body. It combines exception metadata, request context, and configured options into a consistent payload.
Expected output includes standard ProblemDetail fields such as status, title/detail, and instance/path, plus an application-specific code extension. This factory is the main response-shape boundary and should remain the sole owner of field-selection rules.
Configuration and Fallback Policy
src/main/java/io/github/daoud/problemapper/properties/ProblemMapperProperties.java represents the problem-mapper.* configuration surface. It controls enablement, inclusion of path, timestamp, and exception-class information, plus fallback code and message behavior.
The fallback policy is significant: annotated exceptions produce intentional client-facing errors; all others become a configured internal-error response rather than leaking implementation details by default.
Runtime, Packaging, and External Dependencies
The artifact is Maven-built via pom.xml and packaged as a Spring Boot starter JAR. Its material runtime dependency is Spring Boot/Spring MVC, especially Spring’s ProblemDetail API and auto-configuration mechanism. There are no databases, queues, remote APIs, or standalone infrastructure components in the repository.
The build output target/problem-mapper-spring-boot-starter-0.0.1-SNAPSHOT.jar confirms this is distributable library packaging; JitPack is the documented external distribution channel.
Main entry points: ResponseErrorExceptionHandler.java ResponseErrorExceptionHandler · ProblemMapperProperties.java ProblemMapperProperties · ProblemDetailFactory.java ProblemDetailFactory · ProblemMapperAutoConfiguration.java ProblemMapperAutoConfiguration
Components 13
Consumer Application
Supplies requests, exceptions, and starter configuration.
- HTTP Request
- Application Exceptions · Exception classes may declare response metadata.
- problem-mapper.*
Problem Mapper Starter
Library runtime and response-construction pipeline.
- @ResponseError · Declares status, error code, and default message.
src/main/java/io/github/daoud/problemapper/annotation/ResponseError.java - Auto-Configuration Imports · Makes the starter discoverable by Spring Boot.
src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports - ProblemMapperAutoConfiguration · Registers starter runtime beans in the consuming application.
src/main/java/io/github/daoud/problemapper/autoconfigure/ProblemMapperAutoConfiguration.java - ProblemMapperProperties · Controls payload options and fallback policy.
src/main/java/io/github/daoud/problemapper/properties/ProblemMapperProperties.java - ResponseErrorExceptionHandler · Intercepts escaping controller exceptions and selects annotated or fallback handling.
src/main/java/io/github/daoud/problemapper/handler/ResponseErrorExceptionHandler.java - ProblemDetailFactory · Owns ProblemDetail field selection and code extension construction.
src/main/java/io/github/daoud/problemapper/factory/ProblemDetailFactory.java - ProblemDetail Response · RFC-style response with standard fields and an application code.
Spring Boot / MVC
Host framework APIs and startup discovery.
- Spring Boot / Spring MVC · Provides auto-configuration, MVC exception handling, and ProblemDetail.
Other components
- Maven Build
pom.xml - Starter JAR · Packaged Spring Boot starter library.
target/problem-mapper-spring-boot-starter-0.0.1-SNAPSHOT.jar
Connections 16
- Application Exceptions → @ResponseError: annotate
- Auto-Configuration Imports → ProblemMapperAutoConfiguration: discovers
- Spring Boot / Spring MVC → Auto-Configuration Imports: loads
- ProblemMapperAutoConfiguration → ResponseErrorExceptionHandler: registers
- ProblemMapperAutoConfiguration → ProblemMapperProperties: binds
- problem-mapper.* → ProblemMapperProperties: configures
- HTTP Request → Spring Boot / Spring MVC: handled by
- Spring Boot / Spring MVC → ResponseErrorExceptionHandler: routes escaped exceptions
- ResponseErrorExceptionHandler → @ResponseError: inspects exception type
- ResponseErrorExceptionHandler → ProblemMapperProperties: uses fallback policy
- ResponseErrorExceptionHandler → ProblemDetailFactory: delegates construction
- @ResponseError → ProblemDetailFactory: supplies metadata
- ProblemMapperProperties → ProblemDetailFactory: supplies options
- ProblemDetailFactory → ProblemDetail Response: creates
- Maven Build → Starter JAR: packages
- Starter JAR → Spring Boot / Spring MVC: runs within