Skip to content

Instantly share code, notes, and snippets.

@ppyong
Created May 8, 2020 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ppyong/4d47f6546fbfa38d0af769e8f6099d73 to your computer and use it in GitHub Desktop.
Save ppyong/4d47f6546fbfa38d0af769e8f6099d73 to your computer and use it in GitHub Desktop.
@Order(0)
@RestControllerAdvice(annotations = RestController.class)
public class GlobalRestControllerAdvice {
@ExceptionHandler(Exception.class)
public Map<String, Object> handleException(Exception e){
Map<String, Object> errorMap = new HashMap<>();
errorMap.put("code", "E001");
errorMap.put("message", "에러 발생했어요");
return errorMap;
}
}
@Order(1)
@ControllerAdvice(annotations = Controller.class)
public class GlobalControllerAdvice {
@ExceptionHandler(Exception.class)
public String handleException(Exception e){
return "error";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment