Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
170 views
in Technique[技术] by (71.8m points)

Getting cut/part exception message. using java Spring ControllerAdvice

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...