Im using main spring boot service that communicates with 2 sub services (all 3 services are the same application)
The application has spring ControllerAdvice for exception handling.
In a case where sub service return an exception, the error message seems cut while i want to show the full error string.
Cut error message example:
{"errorCode":130,"errorDetails":"MpiManagementServiceException [MpiManagementServiceErrorCode=MpiManagementServiceException [errorCode=130, errorMessage=Failed excecuting command to remote service], errorDetails=404 Not Found: [{"errorMsg":"MpiManagementServiceException [MpiManagementServiceErrorCode=MpiManagementServiceException [errorCode=130, errorMessage=Not Found], errorDetails=Failed zipping design for requested mid: 1... (409 bytes)]]","errorMsg":"MpiManagementServiceException [MpiManagementServiceErrorCode=MpiManagementServiceException [errorCode=130, errorMessage=Failed excecuting command to remote service], errorDetails=MpiManagementServiceException [MpiManagementServiceErrorCode=MpiManagementServiceException [errorCode=130, errorMessage=Failed excecuting command to remote service], errorDetails=404 Not Found: [{"errorMsg":"MpiManagementServiceException [MpiManagementServiceErrorCode=MpiManagementServiceException [errorCode=130, errorMessage=Not Found], errorDetails=Failed zipping design for requested mid: 1... (409 bytes)]]]"}
@ControllerAdvice
public class MpiManagementErrorControllerAdvice
{
@ExceptionHandler(MpiManagementServiceException.class)
@ResponseBody
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public MpiManagementErrorResponse handlePPCError(MpiManagementServiceException mbe, WebRequest request)
{
MpiManagementErrorResponse response = new MpiManagementErrorResponse(mbe);
return response;
}
@ExceptionHandler(BadRequestException.class)
@ResponseBody
@ResponseStatus(HttpStatus.BAD_REQUEST)
public MpiManagementErrorResponse handleBadRequestError(BadRequestException badRequestException, WebRequest request)
{
return new MpiManagementErrorResponse(badRequestException);
}
@ExceptionHandler(ServiceUnavailableException.class)
@ResponseBody
@ResponseStatus(HttpStatus.SERVICE_UNAVAILABLE)
public MpiManagementErrorResponse handleServiceUnavailableError(ServiceUnavailableException serviceUnavailableException, WebRequest request)
{
return new MpiManagementErrorResponse(serviceUnavailableException);
}
@ExceptionHandler(NotFoundException.class)
@ResponseBody
@ResponseStatus(HttpStatus.NOT_FOUND)
public MpiManagementErrorResponse handleNotFoundError(NotFoundException notFoundException, WebRequest request)
{
return new MpiManagementErrorResponse(notFoundException);
}
}
question from:
https://stackoverflow.com/questions/65829026/getting-cut-part-exception-message-using-java-spring-controlleradvice 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…