Last active
November 27, 2018 16:26
-
-
Save Opalo/7c9a17429bcc862cbffe1a2a9e5966c2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Slf4j | |
@Component | |
class DomainExceptionWrapper extends DefaultErrorAttributes { | |
private final ReqTracer tracer; | |
DomainExceptionWrapper(ReqTracer tracer) { | |
super(false); | |
this.tracer = tracer; | |
} | |
@Override | |
public Map<String, Object> getErrorAttributes(ServerRequest request, | |
boolean includeStackTrace) { | |
final var error = getError(request); | |
final var errorAttributes = super.getErrorAttributes(request, false); | |
errorAttributes.put(ErrorAttribute.TRACE_ID.value, tracer.traceId()); | |
if (error instanceof DomainException) { | |
log.debug("Caught an instance of: {}, err: {}", DomainException.class, error); | |
final var errorStatus = ((DomainException) error).getStatus(); | |
errorAttributes.replace(ErrorAttribute.STATUS.value, errorStatus.value()); | |
errorAttributes.replace(ErrorAttribute.ERROR.value, errorStatus.getReasonPhrase()); | |
return errorAttributes; | |
} | |
return errorAttributes; | |
} | |
enum ErrorAttribute { | |
STATUS("status"), | |
ERROR("error"), | |
TRACE_ID("traceId"); | |
private final String value; | |
ErrorAttribute(String value) { | |
this.value = value; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment