ServiceException.java 859 B

123456789101112131415161718192021222324252627282930313233343536
  1. package com.seec.bok.service.exception;
  2. import lombok.Getter;
  3. import lombok.ToString;
  4. import org.springframework.http.HttpStatus;
  5. @Getter
  6. @ToString
  7. public class ServiceException extends RuntimeException {
  8. private int error;
  9. public ServiceException() {
  10. this(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
  11. }
  12. public ServiceException(int error) {
  13. this(error, message(error));
  14. }
  15. public ServiceException(String message) {
  16. this(HttpStatus.INTERNAL_SERVER_ERROR.value(), message);
  17. }
  18. public ServiceException(int error, String message) {
  19. super(message);
  20. this.error = error;
  21. }
  22. private static String message(int error) {
  23. try {
  24. return HttpStatus.valueOf(error).getReasonPhrase();
  25. } catch (IllegalArgumentException e) {
  26. return HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase();
  27. }
  28. }
  29. }