问题描述
我使用的是与 2 个子服务通信的主 Spring Boot 服务(所有 3 个服务都是同一个应用程序) 该应用程序具有用于异常处理的 spring ControllerAdvice。 在子服务返回异常的情况下,错误消息似乎被切断,而我想显示完整的错误字符串。
剪切错误信息示例:
{"errorCode":130,"errorDetails":"MpiManagementServiceException [MpiManagementServiceErrorCode=MpiManagementServiceException [errorCode=130,errorMessage=对远程服务执行命令失败],errorDetails=404 未找到:[{"errorMsg":"MpiManagementServiceException [ MpiManagementServiceErrorCode=MpiManagementServiceException [errorCode=130,errorMessage=Not Found],errorDetails=请求中的压缩设计失败:1... (409 字节)]]","errorMsg":"MpiManagementServiceException [MpiManagementServiceErrorCode =MpiManagementServiceException [errorCode=130,errorMessage=向远程服务执行命令失败],errorDetails=MpiManagementServiceException [MpiManagementServiceErrorCode=MpiManagementServiceException [errorCode=130,errorDetails=404 Not Found: [{"errorM :"MpiManagementServiceException [MpiManagementServiceErrorCode=MpiManagementServiceException [errorCode=130,errorMessage=Not Found],呃rorDetails=请求中段的压缩设计失败:1...(409 字节)]]]"}
@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);
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)