@@ -60,6 +60,19 @@ defmodule GRPC.Integration.ServerTest do
60
60
raise "unknown error(This is a test, please ignore it)"
61
61
end
62
62
63
+ def say_hello ( % { name: "handled error" } , _stream ) do
64
+ % GRPC.RPCError {
65
+ status: GRPC.Status . unauthenticated ( ) ,
66
+ message: "Please authenticate"
67
+ }
68
+ end
69
+
70
+ def say_hello ( % { name: "handled error without message" } , _stream ) do
71
+ % GRPC.RPCError {
72
+ status: GRPC.Status . unauthenticated ( )
73
+ }
74
+ end
75
+
63
76
def say_hello ( _req , _stream ) do
64
77
raise GRPC.RPCError , status: GRPC.Status . unauthenticated ( ) , message: "Please authenticate"
65
78
end
@@ -172,6 +185,33 @@ defmodule GRPC.Integration.ServerTest do
172
185
end )
173
186
end
174
187
188
+ test "return errors for handled errors" do
189
+ run_server ( [ HelloErrorServer ] , fn port ->
190
+ { :ok , channel } = GRPC.Stub . connect ( "localhost:#{ port } " )
191
+ req = Helloworld.HelloRequest . new ( name: "handled error" )
192
+ { :error , reply } = channel |> Helloworld.Greeter.Stub . say_hello ( req )
193
+
194
+ assert % GRPC.RPCError {
195
+ status: GRPC.Status . unauthenticated ( ) ,
196
+ message: "Please authenticate"
197
+ } == reply
198
+ end )
199
+ end
200
+
201
+ test "return errors for handled errors with the default message of the status" do
202
+ run_server ( [ HelloErrorServer ] , fn port ->
203
+ { :ok , channel } = GRPC.Stub . connect ( "localhost:#{ port } " )
204
+ req = Helloworld.HelloRequest . new ( name: "handled error without message" )
205
+ { :error , reply } = channel |> Helloworld.Greeter.Stub . say_hello ( req )
206
+
207
+ assert % GRPC.RPCError {
208
+ status: GRPC.Status . unauthenticated ( ) ,
209
+ message:
210
+ "The request does not have valid authentication credentials for the operation"
211
+ } == reply
212
+ end )
213
+ end
214
+
175
215
test "returns appropriate error for stream requests" do
176
216
run_server ( [ FeatureErrorServer ] , fn port ->
177
217
{ :ok , channel } = GRPC.Stub . connect ( "localhost:#{ port } " )
0 commit comments