*
* Why 502? I quote: <blockquote>HTTP server received an invalid response from a
* server it consulted when acting as a proxy or gateway.</blockquote>
- *
- * This class and the methods are not strictly necessary, the
- * SimpleErrorController is invoked when any controller method takes an uncaught
- * exception, but this approach provides a better response to the front end and
- * doesn't signal internal server error.
*
* Also see:<br>
* https://www.baeldung.com/exception-handling-for-rest-with-spring
// Superclass has "logger" that is exposed here, so use a different name
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
- /**
+ /*
* Generates the response when a REST controller method takes an
- * HttpStatusCodeException. Confusingly, the container first redirects to /error
- * which invokes the
- * {@link org.oransc.ric.portal.dashboard.controller.SimpleErrorController}
- * method, and that response arrives here as the response body.
+ * HttpStatusCodeException.
+ *
+ * @param ex The exception
+ *
+ * @param request The original request
*
- * @param ex
- * The exception
- * @param request
- * The orignal request
* @return A response entity with status code 502 plus some details in the body.
*/
@ExceptionHandler(HttpStatusCodeException.class)
public final ResponseEntity<ErrorTransport> handleHttpStatusCodeException(HttpStatusCodeException ex,
WebRequest request) {
- log.warn("Request {} failed, status code {}", request.getDescription(false), ex.getStatusCode());
+ log.warn("handleHttpStatusCodeException: request {}, status code {}", request.getDescription(false),
+ ex.getStatusCode());
return new ResponseEntity<>(new ErrorTransport(ex.getRawStatusCode(), ex.getResponseBodyAsString(), ex),
HttpStatus.BAD_GATEWAY);
}