获取休息异常消息

时间:2018-10-11 15:31:16

标签: java rest http spring-boot resttemplate

我有一个基本的SpringBoot 2.0.5.RELEASE应用程序。使用Spring Initializer,JPA,嵌入式Tomcat,Thymeleaf模板引擎并将其打包为可执行JAR文件。

我已经创建了这个ExceptionHandler

@RestControllerAdvice
public class RestResponseEntityExceptionHandler extends ResponseEntityExceptionHandler {


    private static final Logger LOG = LoggerFactory.getLogger   (RestResponseEntityExceptionHandler.class);

    public RestResponseEntityExceptionHandler() {
        super();
    }


    @ExceptionHandler({ WorkFlowException.class })
    public ResponseEntity<Object> handleInternalExceptions(final RuntimeException ex, final WebRequest request) {   
        LOG.error("InternalExceptions Code", ex);
        return handleExceptionInternal(ex, ex.getMessage(), new HttpHeaders(), HttpStatus.FORBIDDEN, request);

    }
}

在RestController中,我抛出此异常:

new WorkFlowException("NOT_SIGNED");

在客户端中,我有以下代码:

ResponseEntity<String> response = restTemplate
              .exchange("http://85.30.243.61:1233/theApp/api/v1/users/sign", HttpMethod.POST, entity, String.class);

当我做System.out.println(response.getStatusCode());

我在控制台中收到此消息:

Exception in thread "main" org.springframework.web.client.HttpClientErrorException: 403 null
    at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:94)
    at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:79)
    at org.springframework.web.client.ResponseErrorHandler.handleError(ResponseErrorHandler.java:63)
    at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:730)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:688)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:644)
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:564)

我想知道是否有一种方法可以提取异常 NOT_SIGNED

消息

0 个答案:

没有答案