Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions utils/data_channel_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,35 +56,38 @@ type DataChannelRpcError struct {
}

func (e *DataChannelRpcError) Error() string {
if e.Data != "" {
return fmt.Sprintf("RpcError %d: %s: %s", e.Code, e.Message, e.Data)
}
return fmt.Sprintf("RpcError %d: %s", e.Code, e.Message)
}

func (e *DataChannelRpcError) PsrpcError() psrpc.Error {
switch e.Code {
case DataChannelRpcApplicationError:
return psrpc.NewErrorf(psrpc.Internal, e.Message, "data", e.Data)
return psrpc.NewErrorf(psrpc.Internal, e.Error())
case DataChannelRpcConnectionTimeout:
return psrpc.NewErrorf(psrpc.DeadlineExceeded, e.Message, "data", e.Data)
return psrpc.NewErrorf(psrpc.Canceled, e.Error())
case DataChannelRpcResponseTimeout:
return psrpc.NewErrorf(psrpc.DeadlineExceeded, e.Message, "data", e.Data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does that translate to API error? Feels like DeadlineExceeded is the right one and that will translate to Timeout

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"error": "twirp error cancelled: twirp error unknown: Response timeout%!

return psrpc.NewErrorf(psrpc.Canceled, e.Error())
case DataChannelRpcRecipientDisconnected:
return psrpc.NewErrorf(psrpc.Unavailable, e.Message, "data", e.Data)
return psrpc.NewErrorf(psrpc.Unavailable, e.Error())
case DataChannelRpcResponsePayloadTooLarge:
return psrpc.NewErrorf(psrpc.MalformedResponse, e.Message, "data", e.Data)
return psrpc.NewErrorf(psrpc.MalformedResponse, e.Error())
case DataChannelRpcSendFailed:
return psrpc.NewErrorf(psrpc.Internal, e.Message, "data", e.Data)
return psrpc.NewErrorf(psrpc.Internal, e.Error())
case DataChannelRpcUnsupportedMethod:
return psrpc.NewErrorf(psrpc.InvalidArgument, e.Message, "data", e.Data)
return psrpc.NewErrorf(psrpc.InvalidArgument, e.Error())
case DataChannelRpcRecipientNotFound:
return psrpc.NewErrorf(psrpc.NotFound, e.Message, "data", e.Data)
return psrpc.NewErrorf(psrpc.NotFound, e.Error())
case DataChannelRpcRequestPayloadTooLarge:
return psrpc.NewErrorf(psrpc.MalformedRequest, e.Message, "data", e.Data)
return psrpc.NewErrorf(psrpc.MalformedRequest, e.Error())
case DataChannelRpcUnsupportedServer:
return psrpc.NewErrorf(psrpc.Unimplemented, e.Message, "data", e.Data)
return psrpc.NewErrorf(psrpc.Unimplemented, e.Error())
case DataChannelRpcUnsupportedVersion:
return psrpc.NewErrorf(psrpc.Unimplemented, e.Message, "data", e.Data)
return psrpc.NewErrorf(psrpc.Unimplemented, e.Error())
default:
return psrpc.NewErrorf(psrpc.Internal, e.Message, "data", e.Data)
return psrpc.NewErrorf(psrpc.Internal, e.Error())
}
}

Expand Down
Loading