package com.nju.edu.gitlab.web.handler; import com.nju.edu.gitlab.web.response.ErrorResponse; import com.nju.edu.gitlab.web.response.Response; import org.apache.http.HttpStatus; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestControllerAdvice; import javax.servlet.http.HttpServletResponse; @RestControllerAdvice("{com.nju.edu.gitlab.controller}") public class ApiExceptionHandler { @ExceptionHandler(Exception.class) @ResponseBody public Response handle(HttpServletResponse response, Exception exception) { int error = HttpStatus.SC_INTERNAL_SERVER_ERROR; response.setStatus(error); return new ErrorResponse(error, exception.getMessage()); } }