java - Spring RestTemplate handle custom status code -
i should call service application can return unusual http status codes, such 230, 240 etc. default error handler i'm getting:
servlet.service() servlet [dispatcher] in context path [] threw exception [request processing failed; nested exception org.springframework.web.client.unknownhttpstatuscodeexception: unknown status code [230] null] root cause...   when use custom error handler can avoid this:
@override     public boolean haserror(clienthttpresponse response) throws ioexception {          int status = response.getrawstatuscode();         if (status >= 200 && status <= 299)             return false;          httpstatus statuscode = response.getstatuscode();         if (statuscode.is2xxsuccessful())             return false;         httpstatus.series series = statuscode.series();         return (httpstatus.series.client_error.equals(series)                 || httpstatus.series.server_error.equals(series));     }   but when resttmplate tries retrieve falls same exception in messagebodyclienthttpresponsewrapper:
public boolean hasmessagebody() throws ioexception {         httpstatus responsestatus = this.getstatuscode();         if (responsestatus.is1xxinformational() || responsestatus == httpstatus.no_content ||                 responsestatus == httpstatus.not_modified) {             return false;         }         else if (this.getheaders().getcontentlength() == 0) {             return false;         }         return true;     }   how can response body correctly?
 
 
wiki
 
  
Comments
Post a Comment