Error handling
This commit is contained in:
parent
bacc2da529
commit
4d00504612
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<? extends OverflowRuntimeException> clazz) {
|
||||
super(Status.fromCode(Status.Code.UNKNOWN).withDescription(clazz.getSimpleName()));
|
||||
public OverflowRuntimeException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user