Skip to content

Commit

Permalink
grpc: handle error response
Browse files Browse the repository at this point in the history
  • Loading branch information
gagliardetto committed Jun 12, 2024
1 parent d2f9c68 commit 7c9830e
Show file tree
Hide file tree
Showing 2 changed files with 267 additions and 75 deletions.
51 changes: 48 additions & 3 deletions grpc-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,22 @@ func (multi *MultiEpoch) Get(ser old_faithful_grpc.OldFaithful_GetServer) error
if err != nil {
gerr, ok := status.FromError(err)
if ok {
return status.Errorf(gerr.Code(), "request %d; failed to get block: %v", id, gerr.Message())
return ser.Send(&old_faithful_grpc.GetResponse{
Id: id,
Response: &old_faithful_grpc.GetResponse_Error{
Error: &old_faithful_grpc.GetResponseError{
Code: func() old_faithful_grpc.GetResponseErrorCode {
switch gerr.Code() {
case codes.NotFound:
return old_faithful_grpc.GetResponseErrorCode_NOT_FOUND
default:
return old_faithful_grpc.GetResponseErrorCode_INTERNAL
}
}(),
Message: gerr.Message(),
},
},
})
}
return status.Errorf(codes.Internal, "request %d; failed to get block: %v", id, err)
}
Expand All @@ -472,7 +487,22 @@ func (multi *MultiEpoch) Get(ser old_faithful_grpc.OldFaithful_GetServer) error
if err != nil {
gerr, ok := status.FromError(err)
if ok {
return status.Errorf(gerr.Code(), "request %d; failed to get transaction: %v", id, gerr.Message())
return ser.Send(&old_faithful_grpc.GetResponse{
Id: id,
Response: &old_faithful_grpc.GetResponse_Error{
Error: &old_faithful_grpc.GetResponseError{
Code: func() old_faithful_grpc.GetResponseErrorCode {
switch gerr.Code() {
case codes.NotFound:
return old_faithful_grpc.GetResponseErrorCode_NOT_FOUND
default:
return old_faithful_grpc.GetResponseErrorCode_INTERNAL
}
}(),
Message: gerr.Message(),
},
},
})
}
return status.Errorf(codes.Internal, "request %d; failed to get transaction: %v", id, err)
}
Expand All @@ -488,7 +518,22 @@ func (multi *MultiEpoch) Get(ser old_faithful_grpc.OldFaithful_GetServer) error
if err != nil {
gerr, ok := status.FromError(err)
if ok {
return status.Errorf(gerr.Code(), "request %d; failed to get version: %v", id, gerr.Message())
return ser.Send(&old_faithful_grpc.GetResponse{
Id: id,
Response: &old_faithful_grpc.GetResponse_Error{
Error: &old_faithful_grpc.GetResponseError{
Code: func() old_faithful_grpc.GetResponseErrorCode {
switch gerr.Code() {
case codes.NotFound:
return old_faithful_grpc.GetResponseErrorCode_NOT_FOUND
default:
return old_faithful_grpc.GetResponseErrorCode_INTERNAL
}
}(),
Message: gerr.Message(),
},
},
})
}
return status.Errorf(codes.Internal, "request %d; failed to get version: %v", id, err)
}
Expand Down
Loading

0 comments on commit 7c9830e

Please sign in to comment.