Class DefaultWebResponseMapper
java.lang.Object
io.fluxzero.sdk.web.DefaultWebResponseMapper
- All Implemented Interfaces:
ResponseMapper, WebResponseMapper
Default implementation of
WebResponseMapper that converts handler return values into WebResponse objects.
This mapper is used internally to standardize responses from @HandleWeb methods or forwarded HTTP requests.
It maps return values based on their type, applying common HTTP status codes and payload formatting conventions.
Mapping Rules
The logic follows these conventions:- If the response is already a
WebResponse, it is returned unchanged - If the response is a known
Throwable, a corresponding HTTP error code and message are assigned:ValidationExceptionorDeserializationException→ 400 Bad RequestUnauthorizedExceptionorUnauthenticatedException→ 401 Unauthorized- other
FunctionalExceptions → 403 Forbidden TimeoutExceptionor Fluxzero's ownTimeoutException→ 503 Service Unavailable- Any other
Throwable→ 500 Internal Server Error
- If the response is
null, the status is set to 204 No Content - Otherwise, the response is treated as a normal payload with status 200 OK
In all cases, the provided Metadata is added to the resulting response.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionMaps a raw handler return value and associated metadata into aWebResponse.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface WebResponseMapper
map
-
Constructor Details
-
DefaultWebResponseMapper
public DefaultWebResponseMapper()
-
-
Method Details
-
map
Maps a raw handler return value and associated metadata into aWebResponse.- Specified by:
mapin interfaceResponseMapper- Specified by:
mapin interfaceWebResponseMapper- Parameters:
response- the return value (may be aWebResponse, a regular object, or aThrowable)metadata- metadata to attach to the response- Returns:
- a mapped
WebResponseobject
-