{"action":"opened","issue":{"url":"https://api.github.com/repos/spring-cloud/spring-cloud-netflix/issues/318","labels_url":"https://api.github.com/repos/spring-cloud/spring-cloud-netflix/issues/318/labels{/name}","comments_url":"https://api.github.com/repos/spring-cloud/spring-cloud-netflix/issues/318/comments","events_url":"https://api.github.com/repos/spring-cloud/spring-cloud-netflix/issues/318/events","html_url":"https://github.com/spring-cloud/spring-cloud-netflix/issues/318","id":71290456,"number":318,"title":"Implement Feign ErrorDecoder that is aware of spring HttpClientErrorException and HttpServerErrorException","user":{"login":"xyloman","id":910329,"avatar_url":"https://avatars.githubusercontent.com/u/910329?v=3","gravatar_id":"","url":"https://api.github.com/users/xyloman","html_url":"https://github.com/xyloman","followers_url":"https://api.github.com/users/xyloman/followers","following_url":"https://api.github.com/users/xyloman/following{/other_user}","gists_url":"https://api.github.com/users/xyloman/gists{/gist_id}","starred_url":"https://api.github.com/users/xyloman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xyloman/subscriptions","organizations_url":"https://api.github.com/users/xyloman/orgs","repos_url":"https://api.github.com/users/xyloman/repos","events_url":"https://api.github.com/users/xyloman/events{/privacy}","received_events_url":"https://api.github.com/users/xyloman/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-04-27T13:52:12Z","updated_at":"2015-04-27T13:52:12Z","closed_at":null,"body":"In our consumption of feign we ran into an issue where we need access to the response status code and response body associated to a client error.  We have implemented the following ErrorDecoder implementation in our code base and wanted to share it with the community. It seems like others that are familiar with spring RestOperations are accustom to HttpClientErrorException and HttpServerErrorException exception trees versus the stripped down FeignException.  The only concern with the implementation below is how to handle the response body if an exception where to happen during the copying process from feign response to a given instance of spring HttpStatusCodeException:\r\n```java\r\npublic class SpringWebClientErrorDecoder implements ErrorDecoder {\r\n\r\n\tprivate ErrorDecoder delegate = new ErrorDecoder.Default();\r\n\r\n\t@Override\r\n\tpublic Exception decode(String methodKey, Response response) {\r\n\t\tHttpHeaders responseHeaders = new HttpHeaders();\r\n\t\tresponse.headers().entrySet().stream()\r\n\t\t\t\t.forEach(entry -> responseHeaders.put(entry.getKey(), new ArrayList<>(entry.getValue())));\r\n\r\n\t\tHttpStatus statusCode = HttpStatus.valueOf(response.status());\r\n\t\tString statusText = response.reason();\r\n\r\n\t\tbyte[] responseBody;\r\n\t\ttry {\r\n\t\t\tresponseBody = IOUtils.toByteArray(response.body().asInputStream());\r\n\t\t} catch (IOException e) {\r\n\t\t\tthrow new RuntimeException(\"Failed to process response body.\", e);\r\n\t\t}\r\n\r\n\t\tif (response.status() >= 400 && response.status() <= 499) {\r\n\t\t\treturn new HttpClientErrorException(statusCode, statusText, responseHeaders, responseBody, null);\r\n\t\t}\r\n\r\n\t\tif (response.status() >= 500 && response.status() <= 599) {\r\n\t\t\treturn new HttpServerErrorException(statusCode, statusText, responseHeaders, responseBody, null);\r\n\t\t}\r\n\t\treturn delegate.decode(methodKey, response);\r\n\t}\r\n}\r\n```\r\n"}}