2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 AT&T Intellectual Property and Nokia
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ========================LICENSE_END===================================
21 package org.oransc.ric.portal.dashboard.controller;
23 import java.lang.invoke.MethodHandles;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27 import org.springframework.boot.web.servlet.error.ErrorController;
28 import org.springframework.http.MediaType;
29 import org.springframework.stereotype.Controller;
30 import org.springframework.web.bind.annotation.GetMapping;
31 import org.springframework.web.bind.annotation.RequestMapping;
33 import springfox.documentation.annotations.ApiIgnore;
36 * Provides a controller which is invoked on any error within the Spring-managed
37 * context, including page not found, and redirects the caller to a custom error
38 * page. The caller is also redirected to this page if a REST controller takes
39 * an uncaught exception.
41 * If trace is requested via request parameter ("?trace=true") and available,
42 * adds stack trace information to the standard JSON error response.
44 * Excluded from Swagger API documentation.
46 * https://stackoverflow.com/questions/25356781/spring-boot-remove-whitelabel-error-page
47 * https://www.baeldung.com/spring-boot-custom-error-page
52 @RequestMapping(value = SimpleErrorController.ERROR_PATH, produces = MediaType.APPLICATION_JSON_VALUE)
53 public class SimpleErrorController implements ErrorController {
55 private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
57 public static final String ERROR_PATH = "/error";
60 public String getErrorPath() {
61 logger.warn("getErrorPath");
66 public String handleError() {
67 logger.warn("handleError");
68 // Return the name of the page INCLUDING suffix, which I guess is a "view" name.
69 // Just "error" is not enough, but don't seem to need a ModelAndView object.