diff --git a/src/main/java/com/loafle/overflow/commons/exception/OverflowException.java b/src/main/java/com/loafle/overflow/commons/exception/OverflowException.java index bb3cdf4..24eabdd 100644 --- a/src/main/java/com/loafle/overflow/commons/exception/OverflowException.java +++ b/src/main/java/com/loafle/overflow/commons/exception/OverflowException.java @@ -1,10 +1,21 @@ package com.loafle.overflow.commons.exception; import io.grpc.Status; -import io.grpc.StatusException; -public class OverflowException extends StatusException { - public OverflowException(Status status) { - super(status); +public class OverflowException extends Exception { + protected Status.Code code; + + public OverflowException(Status.Code code) { + super(); + this.code = code; + } + + public OverflowException(Status.Code code, String message) { + super(message); + this.code = code; + } + + public Status.Code getCode() { + return code; } } diff --git a/src/main/java/com/loafle/overflow/commons/exception/OverflowRuntimeException.java b/src/main/java/com/loafle/overflow/commons/exception/OverflowRuntimeException.java index 5f72a99..b632e72 100644 --- a/src/main/java/com/loafle/overflow/commons/exception/OverflowRuntimeException.java +++ b/src/main/java/com/loafle/overflow/commons/exception/OverflowRuntimeException.java @@ -1,10 +1,11 @@ package com.loafle.overflow.commons.exception; -import io.grpc.Status; -import io.grpc.StatusRuntimeException; +public class OverflowRuntimeException extends RuntimeException { + public OverflowRuntimeException() { + super(); + } -public class OverflowRuntimeException extends StatusRuntimeException { - public OverflowRuntimeException(Class clazz) { - super(Status.fromCode(Status.Code.UNKNOWN).withDescription(clazz.getSimpleName())); + public OverflowRuntimeException(String message) { + super(message); } } diff --git a/src/main/java/com/loafle/overflow/module/member/exception/EmailNotConfirmedException.java b/src/main/java/com/loafle/overflow/module/member/exception/EmailNotConfirmedException.java index 3aeef7b..26dd063 100644 --- a/src/main/java/com/loafle/overflow/module/member/exception/EmailNotConfirmedException.java +++ b/src/main/java/com/loafle/overflow/module/member/exception/EmailNotConfirmedException.java @@ -4,6 +4,10 @@ import com.loafle.overflow.commons.exception.OverflowRuntimeException; public class EmailNotConfirmedException extends OverflowRuntimeException { public EmailNotConfirmedException() { - super(EmailNotConfirmedException.class); + super(); + } + + public EmailNotConfirmedException(String message) { + super(message); } } \ No newline at end of file diff --git a/src/main/java/com/loafle/overflow/module/member/exception/SignInIdNotExistException.java b/src/main/java/com/loafle/overflow/module/member/exception/SignInIdNotExistException.java index 74c0022..654c422 100644 --- a/src/main/java/com/loafle/overflow/module/member/exception/SignInIdNotExistException.java +++ b/src/main/java/com/loafle/overflow/module/member/exception/SignInIdNotExistException.java @@ -4,6 +4,10 @@ import com.loafle.overflow.commons.exception.OverflowRuntimeException; public class SignInIdNotExistException extends OverflowRuntimeException { public SignInIdNotExistException() { - super(SignInIdNotExistException.class); + super(); + } + + public SignInIdNotExistException(String message) { + super(message); } } diff --git a/src/main/java/com/loafle/overflow/module/member/exception/SignInPwNotMatchException.java b/src/main/java/com/loafle/overflow/module/member/exception/SignInPwNotMatchException.java index 2b1d2e3..d3adbff 100644 --- a/src/main/java/com/loafle/overflow/module/member/exception/SignInPwNotMatchException.java +++ b/src/main/java/com/loafle/overflow/module/member/exception/SignInPwNotMatchException.java @@ -4,6 +4,10 @@ import com.loafle.overflow.commons.exception.OverflowRuntimeException; public class SignInPwNotMatchException extends OverflowRuntimeException { public SignInPwNotMatchException() { - super(SignInPwNotMatchException.class); + super(); + } + + public SignInPwNotMatchException(String message) { + super(message); } } diff --git a/src/main/java/com/loafle/overflow/proxy/ServiceInvoker.java b/src/main/java/com/loafle/overflow/proxy/ServiceInvoker.java index 40012b5..4cd5ad8 100644 --- a/src/main/java/com/loafle/overflow/proxy/ServiceInvoker.java +++ b/src/main/java/com/loafle/overflow/proxy/ServiceInvoker.java @@ -8,9 +8,9 @@ import com.loafle.overflow.proxy.exception.InvalidParameterException; import com.loafle.overflow.proxy.exception.InvalidRequestException; import com.loafle.overflow.proxy.exception.NoSuchMethodException; import com.loafle.overflow.proxy.exception.NoSuchServiceException; -import org.codehaus.jackson.JsonGenerationException; +import io.grpc.Status; +import io.grpc.StatusRuntimeException; import org.codehaus.jackson.map.DeserializationConfig; -import org.codehaus.jackson.map.JsonMappingException; import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.type.JavaType; import org.springframework.aop.support.AopUtils; @@ -199,4 +199,5 @@ public class ServiceInvoker { return jsonInString; } + } diff --git a/src/main/java/com/loafle/overflow/proxy/ServiceProxy.java b/src/main/java/com/loafle/overflow/proxy/ServiceProxy.java index d6c140e..a56594d 100644 --- a/src/main/java/com/loafle/overflow/proxy/ServiceProxy.java +++ b/src/main/java/com/loafle/overflow/proxy/ServiceProxy.java @@ -3,8 +3,12 @@ package com.loafle.overflow.proxy; import com.loafle.overflow.api.OverflowApiServerGrpc; import com.loafle.overflow.api.ServerInput; import com.loafle.overflow.api.ServerOutput; +import com.loafle.overflow.commons.exception.OverflowException; +import com.loafle.overflow.commons.exception.OverflowRuntimeException; import io.grpc.ServerBuilder; +import io.grpc.Status; import io.grpc.StatusException; +import io.grpc.StatusRuntimeException; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -73,15 +77,28 @@ public class ServiceProxy { .build(); responseObserver.onNext(reply); responseObserver.onCompleted(); - } catch (StatusException e) { + } catch (OverflowException e) { logger.warning(e.toString()); - responseObserver.onError(e); - } catch (Throwable e) { - responseObserver.onError(e); + responseObserver.onError(convertException(e)); + } catch (OverflowRuntimeException e) { + logger.warning(e.toString()); + responseObserver.onError(convertException(e)); } } + protected StatusRuntimeException convertException(OverflowRuntimeException e) { + String message = String.format("%s|%s", e.getClass().getSimpleName(), e.getMessage()); + Status status = Status.fromCode(Status.Code.INTERNAL).withDescription(message); + return new StatusRuntimeException(status); + } + + protected StatusException convertException(OverflowException e) { + String message = String.format("%s|%s", e.getClass().getSimpleName(), e.getMessage()); + Status status = Status.fromCode(e.getCode()).withDescription(message); + return new StatusException(status); + } + } } diff --git a/src/main/java/com/loafle/overflow/proxy/exception/InvalidParameterException.java b/src/main/java/com/loafle/overflow/proxy/exception/InvalidParameterException.java index c5e6ae2..f235d31 100644 --- a/src/main/java/com/loafle/overflow/proxy/exception/InvalidParameterException.java +++ b/src/main/java/com/loafle/overflow/proxy/exception/InvalidParameterException.java @@ -4,7 +4,12 @@ import com.loafle.overflow.commons.exception.OverflowException; import io.grpc.Status; public class InvalidParameterException extends OverflowException { + private static final Status.Code code = Status.Code.INVALID_ARGUMENT; public InvalidParameterException() { - super(Status.fromCode(Status.Code.INVALID_ARGUMENT).withDescription(InvalidParameterException.class.getSimpleName())); + super(code); + } + + public InvalidParameterException(String message) { + super(code, message); } } diff --git a/src/main/java/com/loafle/overflow/proxy/exception/InvalidRequestException.java b/src/main/java/com/loafle/overflow/proxy/exception/InvalidRequestException.java index 7d89fca..840bec3 100644 --- a/src/main/java/com/loafle/overflow/proxy/exception/InvalidRequestException.java +++ b/src/main/java/com/loafle/overflow/proxy/exception/InvalidRequestException.java @@ -4,7 +4,12 @@ import com.loafle.overflow.commons.exception.OverflowException; import io.grpc.Status; public class InvalidRequestException extends OverflowException { + private static final Status.Code code = Status.Code.UNKNOWN; public InvalidRequestException() { - super(Status.fromCode(Status.Code.INTERNAL).withDescription(InvalidRequestException.class.getSimpleName())); + super(code); + } + + public InvalidRequestException(String message) { + super(code, message); } } diff --git a/src/main/java/com/loafle/overflow/proxy/exception/NoSuchMethodException.java b/src/main/java/com/loafle/overflow/proxy/exception/NoSuchMethodException.java index 003c74a..c05a12d 100644 --- a/src/main/java/com/loafle/overflow/proxy/exception/NoSuchMethodException.java +++ b/src/main/java/com/loafle/overflow/proxy/exception/NoSuchMethodException.java @@ -4,7 +4,12 @@ import com.loafle.overflow.commons.exception.OverflowException; import io.grpc.Status; public class NoSuchMethodException extends OverflowException { + private static final Status.Code code = Status.Code.UNIMPLEMENTED; public NoSuchMethodException() { - super(Status.fromCode(Status.Code.UNIMPLEMENTED).withDescription(NoSuchMethodException.class.getSimpleName())); + super(code); + } + + public NoSuchMethodException(String message) { + super(code, message); } } diff --git a/src/main/java/com/loafle/overflow/proxy/exception/NoSuchServiceException.java b/src/main/java/com/loafle/overflow/proxy/exception/NoSuchServiceException.java index f84cd73..473ad47 100644 --- a/src/main/java/com/loafle/overflow/proxy/exception/NoSuchServiceException.java +++ b/src/main/java/com/loafle/overflow/proxy/exception/NoSuchServiceException.java @@ -4,7 +4,12 @@ import com.loafle.overflow.commons.exception.OverflowException; import io.grpc.Status; public class NoSuchServiceException extends OverflowException { + private static final Status.Code code = Status.Code.UNIMPLEMENTED; public NoSuchServiceException() { - super(Status.fromCode(Status.Code.UNAVAILABLE).withDescription(NoSuchServiceException.class.getSimpleName())); + super(code); + } + + public NoSuchServiceException(String message) { + super(code, message); } }