1 /*
2 * Copyright 2018-2022 Medical Information Systems Research Group (https://medical.zcu.cz),
3 * Department of Computer Science and Engineering, University of West Bohemia.
4 * Address: Univerzitni 8, 306 14 Plzen, Czech Republic.
5 *
6 * Author Petr Vcelak (vcelak@kiv.zcu.cz).
7 *
8 * This file is part of MRECore project.
9 *
10 * MRECore is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License.
13 *
14 * MRECore is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MRECore. If not, see <http://www.gnu.org/licenses/>.
21 */
22 package cz.zcu.mre.controller;
23
24 import org.springframework.web.bind.annotation.ControllerAdvice;
25 import org.springframework.web.context.request.WebRequest;
26 import org.springframework.web.servlet.ModelAndView;
27 import com.google.common.base.Throwables;
28
29 /**
30 * General error handler for the application.
31 *
32 * @author Petr Vcelak (vcelak@kiv.zcu.cz)
33 */
34 @ControllerAdvice
35 class ExceptionHandler {
36
37 /**
38 * Handle exceptions thrown by handlers.
39 */
40 @org.springframework.web.bind.annotation.ExceptionHandler(value = Exception.class)
41 public ModelAndView exception(Exception exception, WebRequest request) {
42 ModelAndView modelAndView = new ModelAndView(ErrorController.ERROR_GENERAL);
43 modelAndView.addObject("errorMessage", Throwables.getRootCause(exception));
44 // Print all exepctions.
45 exception.printStackTrace();
46 return modelAndView;
47 }
48 }