- /**
- * Logs the error and generates a JSON response when a REST controller method
- * takes a RestClientResponseException. This is thrown by the Http client when a
- * remote method returns a non-2xx code. All the controller methods are proxies
- * in that they just forward the request along to a remote system, so if that
- * remote system fails, return 502 plus some details about the failure, rather
- * than the generic 500 that Spring-Boot will return on an uncaught exception.
- *
- * Why 502? I quote: <blockquote>HTTP server received an invalid response from a
- * server it consulted when acting as a proxy or gateway.</blockquote>
- *
- * @param ex
- * The exception
- *
- * @param request
- * The original request
- *
- * @return A response entity with status code 502 plus some details in the body.
- */
- @ExceptionHandler({ RestClientResponseException.class })
- public final ResponseEntity<ErrorTransport> handleProxyMethodException(Exception ex, WebRequest request) {
- // Capture the full stack trace in the log.
- log.error("handleProxyMethodException: request {}, exception {}", request.getDescription(false), ex);
- if (ex instanceof HttpStatusCodeException) {
- HttpStatusCodeException hsce = (HttpStatusCodeException) ex;
- return new ResponseEntity<>(new ErrorTransport(hsce.getRawStatusCode(), hsce.getResponseBodyAsString(),
- ex.toString(), request.getDescription(false)), HttpStatus.BAD_GATEWAY);
- } else {
- return new ResponseEntity<>(new ErrorTransport(500, ex), HttpStatus.BAD_GATEWAY);
- }
- }
+ /**
+ * Logs the error and generates a JSON response when a REST controller method
+ * takes a RestClientResponseException. This is thrown by the Http client when a
+ * remote method returns a non-2xx code. All the controller methods are proxies
+ * in that they just forward the request along to a remote system, so if that
+ * remote system fails, return 502 plus some details about the failure, rather
+ * than the generic 500 that Spring-Boot will return on an uncaught exception.
+ *
+ * Why 502? I quote: <blockquote>HTTP server received an invalid response from a
+ * server it consulted when acting as a proxy or gateway.</blockquote>
+ *
+ * @param ex
+ * The exception
+ *
+ * @param request
+ * The original request
+ *
+ * @return A response entity with status code 502 plus some details in the body.
+ */
+ @ExceptionHandler({RestClientResponseException.class})
+ public final ResponseEntity<ErrorTransport> handleProxyMethodException(Exception ex, WebRequest request) {
+ // Capture the full stack trace in the log.
+ log.error("handleProxyMethodException: request {}, exception {}", request.getDescription(false),
+ ex.getMessage());
+ if (ex instanceof HttpStatusCodeException) {
+ HttpStatusCodeException hsce = (HttpStatusCodeException) ex;
+ return new ResponseEntity<>(new ErrorTransport(hsce.getRawStatusCode(), hsce.getResponseBodyAsString(),
+ ex.toString(), request.getDescription(false)), HttpStatus.BAD_GATEWAY);
+ } else {
+ return new ResponseEntity<>(new ErrorTransport(500, ex), HttpStatus.BAD_GATEWAY);
+ }
+ }