blob: a3e697b4dedcaeb30f5f6bf7122efad19c23fc02 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
package com.juick.www.controllers;
import com.juick.server.util.HttpBadRequestException;
import com.juick.server.util.HttpForbiddenException;
import com.juick.server.util.HttpNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
/**
* Created by aalexeev on 12/12/16.
*/
@ControllerAdvice
public class ErrorController {
private static Logger logger = LoggerFactory.getLogger(ErrorController.class);
@ExceptionHandler(HttpBadRequestException.class)
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
public String badRequest() {
return "layout/error";
}
@ExceptionHandler(HttpForbiddenException.class)
@ResponseStatus(value = HttpStatus.FORBIDDEN)
public String forbidden() {
return "layout/error";
}
@ExceptionHandler(HttpNotFoundException.class)
@ResponseStatus(value = HttpStatus.NOT_FOUND)
public String notFound() {
return "layout/error";
}
@ExceptionHandler(Throwable.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public String exception(final Throwable throwable, final Model model) {
logger.error("Exception during execution of SpringSecurity application", throwable);
String errorMessage = (throwable != null ? throwable.getMessage() : "Unknown error");
model.addAttribute("errorMessage", errorMessage);
return "layout/error";
}
}
|