java - How to handle error responses using spring rest client -
i trying better handle bad responses when using sprint rest client. code follows:
responseentity<foo> response = null; try { response = resttemplate.exchange(uri, httpmethod.get, new httpentity<>(new httpheaders()), foo.class); catch (restclientexception rce) { //what here? }
this works great long there no error. problem when corresponding web service returns error (or times out), exception. there no enum status code handle wish. error message useful. not. usually, if corresponding server returns html error page, message object cannot created, specific error swallowed.
any ideas?
what can rce.getmostspecificcause()
? maybe there more information.
you can catch httpstatuscodeexception
direct subclass of restclientexception
more generic. there lot of exceptions can catch more specific restclientexception
e.g.
public class httpservererrorexception extends httpstatuscodeexception exception thrown when http 5xx received.
look @ docs restclientexception
.
Comments
Post a Comment