test master 변경

This commit is contained in:
현성필
2024-01-23 11:24:09 +09:00
parent 75a695897d
commit 91e902af25
121 changed files with 329 additions and 338 deletions
@@ -0,0 +1,34 @@
package com.eactive.testmaster.common.exception;
import java.time.LocalDateTime;
public class CustomErrorResponse {
private LocalDateTime timestamp;
private String error;
private int status;
public LocalDateTime getTimestamp() {
return timestamp;
}
public void setTimestamp(LocalDateTime timestamp) {
this.timestamp = timestamp;
}
public String getError() {
return error;
}
public void setError(String error) {
this.error = error;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
}
@@ -0,0 +1,45 @@
package com.eactive.testmaster.common.exception;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
import java.time.LocalDateTime;
@Order(1)
@RestControllerAdvice(annotations = RestController.class)
public class CustomGlobalExceptionHandler extends ResponseEntityExceptionHandler {
@ExceptionHandler(NotFoundException.class)
public ResponseEntity<CustomErrorResponse> customHandleNotFound(Exception ex, WebRequest request) {
CustomErrorResponse errors = new CustomErrorResponse();
errors.setTimestamp(LocalDateTime.now());
errors.setError(ex.getMessage());
errors.setStatus(HttpStatus.NOT_FOUND.value());
return new ResponseEntity<>(errors, HttpStatus.NOT_FOUND);
}
@ExceptionHandler(RuntimeException.class)
public ResponseEntity<CustomErrorResponse> customHandleRuntime(Exception ex, WebRequest request) {
CustomErrorResponse errors = new CustomErrorResponse();
errors.setTimestamp(LocalDateTime.now());
errors.setError(ex.getMessage());
errors.setStatus(HttpStatus.BAD_REQUEST.value());
return new ResponseEntity<>(errors, HttpStatus.BAD_REQUEST);
}
@ExceptionHandler(UserNotLoginException.class)
public ResponseEntity<CustomErrorResponse> customHandleUserNotLogin(Exception ex, WebRequest request) {
CustomErrorResponse errors = new CustomErrorResponse();
errors.setTimestamp(LocalDateTime.now());
errors.setError(ex.getMessage());
errors.setStatus(HttpStatus.UNAUTHORIZED.value());
return new ResponseEntity<>(errors, HttpStatus.UNAUTHORIZED);
}
}
@@ -0,0 +1,7 @@
package com.eactive.testmaster.common.exception;
public class NotFoundException extends IllegalArgumentException {
public NotFoundException(String message) {
super(message);
}
}
@@ -0,0 +1,39 @@
package com.eactive.testmaster.common.exception;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
@Controller
public class PortalErrorController implements ErrorController {
@GetMapping("/error")
public String handleError(HttpServletRequest request, ModelMap model) {
Object status = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);
if (status != null) {
model.addAttribute("status", status);
return "error";
}
return "redirect:/";
}
@PostMapping("/error")
public String handleErrorPost(HttpServletRequest request, ModelMap model) {
Object status = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);
if (status != null) {
model.addAttribute("status", status);
return "error";
}
return "redirect:/";
}
}
@@ -0,0 +1,34 @@
package com.eactive.testmaster.common.exception;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
@ControllerAdvice(annotations = Controller.class)
@Order(2)
public class PortalGlobalExceptionHandler {
private final Logger log = LoggerFactory.getLogger(getClass());
@ExceptionHandler(value = NotFoundException.class)
public ModelAndView handleIllegalArgumentException(HttpServletRequest request, NotFoundException ex) {
log.error(ex.getMessage());
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("error");
modelAndView.addObject("exception", ex);
return modelAndView;
}
@ExceptionHandler(value = UserNotLoginException.class)
public ModelAndView handleIllegalArgumentException(HttpServletRequest request, UserNotLoginException ex) {
return new ModelAndView("redirect:/login");
}
}
@@ -0,0 +1,8 @@
package com.eactive.testmaster.common.exception;
public class ServerNotFoundException extends RuntimeException {
public ServerNotFoundException(String message) {
super(message);
}
}
@@ -0,0 +1,7 @@
package com.eactive.testmaster.common.exception;
public class UserNotFoundException extends RuntimeException {
public UserNotFoundException(String message) {
super(message);
}
}
@@ -0,0 +1,8 @@
package com.eactive.testmaster.common.exception;
public class UserNotLoginException extends RuntimeException {
public UserNotLoginException() {
super("User not login");
}
}
@@ -0,0 +1,8 @@
package com.eactive.testmaster.common.exception;
public class UserPasswordResetException extends RuntimeException {
public UserPasswordResetException(String message) {
super(message);
}
}