Spring RestTemplate invoking webservice with errors and analyze status code

前端 未结 5 920
执笔经年
执笔经年 2020-12-07 17:39

I designed a webservice to perform a task if request parameters are OK, or return 401 Unauthorized HTTP status code if request parameters are wrong or empty.

I\'m us

5条回答
  •  温柔的废话
    2020-12-07 18:27

    As an alternative to the solution presented by nilesh, you could also use spring class DefaultResponseErrorHandler. You also need to ovveride its hasError(HttpStatus) method so it does not throw exception on non-successful result.

    restTemplate.setErrorHandler(new DefaultResponseErrorHandler(){
        protected boolean hasError(HttpStatus statusCode) {
            return false;
        }});
    

提交回复
热议问题