X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=webapp-backend%2Fsrc%2Fmain%2Fjava%2Forg%2Foransc%2Fric%2Fportal%2Fdashboard%2Fcontroller%2FSimpleErrorController.java;h=b603840d74d8ab3e59a6b967fd6c41e84b6e3dc7;hb=e020df304f6faa1d90f64ddea14407aec1c15dcb;hp=3102e4e14282edecc8c74451f325a92aa129e373;hpb=c7a3ec6561b3b2ce1facbec092305977c3eba665;p=portal%2Fric-dashboard.git diff --git a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/SimpleErrorController.java b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/SimpleErrorController.java index 3102e4e1..b603840d 100644 --- a/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/SimpleErrorController.java +++ b/webapp-backend/src/main/java/org/oransc/ric/portal/dashboard/controller/SimpleErrorController.java @@ -2,7 +2,7 @@ * ========================LICENSE_START================================= * O-RAN-SC * %% - * Copyright (C) 2019 AT&T Intellectual Property and Nokia + * Copyright (C) 2019 AT&T Intellectual Property * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,14 +21,20 @@ package org.oransc.ric.portal.dashboard.controller; import java.lang.invoke.MethodHandles; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.web.servlet.error.ErrorAttributes; import org.springframework.boot.web.servlet.error.ErrorController; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.context.request.ServletWebRequest; import springfox.documentation.annotations.ApiIgnore; @@ -56,6 +62,13 @@ public class SimpleErrorController implements ErrorController { public static final String ERROR_PATH = "/error"; + private final ErrorAttributes errorAttributes; + + @Autowired + public SimpleErrorController(ErrorAttributes errorAttributes) { + this.errorAttributes = errorAttributes; + } + @Override public String getErrorPath() { logger.warn("getErrorPath"); @@ -63,11 +76,17 @@ public class SimpleErrorController implements ErrorController { } @GetMapping - public String handleError() { - logger.warn("handleError"); + public String handleError(HttpServletRequest request) { + ServletWebRequest servletWebRequest = new ServletWebRequest(request); + Throwable t = errorAttributes.getError(servletWebRequest); + if (t != null) + logger.warn("handleError", t); + Map attributes = errorAttributes.getErrorAttributes(servletWebRequest, true); + // use compact lambda syntax to silence Sonar complaint + attributes.forEach((attribute, value) -> logger.warn("handleError: {} -> {}", attribute, value)); // Return the name of the page INCLUDING suffix, which I guess is a "view" name. // Just "error" is not enough, but don't seem to need a ModelAndView object. return "error.html"; } -} \ No newline at end of file +}