@@ -63,30 +63,26 @@ impl Filter {
63
63
}
64
64
}
65
65
66
- fn handle_error_on_grpc_response ( & self ) {
67
- // todo(adam-cattermole): We need a method of knowing which service is the one currently
68
- // being used (the current action) so that we can get the failure mode
69
- let rls = self
70
- . config
71
- . services
72
- . values ( )
73
- . next ( )
74
- . expect ( "expect a value" ) ;
75
- match rls. failure_mode ( ) {
66
+ fn handle_error_on_grpc_response ( & self , failure_mode : & FailureMode ) {
67
+ match failure_mode {
76
68
FailureMode :: Deny => {
77
69
self . send_http_response ( 500 , vec ! [ ] , Some ( b"Internal Server Error.\n " ) )
78
70
}
79
71
FailureMode :: Allow => self . resume_http_request ( ) ,
80
72
}
81
73
}
82
74
83
- fn process_ratelimit_grpc_response ( & mut self , rl_resp : GrpcMessageResponse ) {
75
+ fn process_ratelimit_grpc_response (
76
+ & mut self ,
77
+ rl_resp : GrpcMessageResponse ,
78
+ failure_mode : & FailureMode ,
79
+ ) {
84
80
match rl_resp {
85
81
GrpcMessageResponse :: RateLimit ( RateLimitResponse {
86
82
overall_code : RateLimitResponse_Code :: UNKNOWN ,
87
83
..
88
84
} ) => {
89
- self . handle_error_on_grpc_response ( ) ;
85
+ self . handle_error_on_grpc_response ( failure_mode ) ;
90
86
}
91
87
GrpcMessageResponse :: RateLimit ( RateLimitResponse {
92
88
overall_code : RateLimitResponse_Code :: OVER_LIMIT ,
@@ -157,16 +153,16 @@ impl Context for Filter {
157
153
self . context_id
158
154
) ;
159
155
160
- let res_body_bytes = match self . get_grpc_call_response_body ( 0 , resp_size) {
161
- Some ( bytes) => bytes,
162
- None => {
163
- warn ! ( "grpc response body is empty!" ) ;
164
- self . handle_error_on_grpc_response ( ) ;
165
- return ;
166
- }
167
- } ;
168
-
169
156
if let Some ( operation) = self . operation_dispatcher . get_operation ( token_id) {
157
+ let failure_mode = & operation. get_failure_mode ( ) ;
158
+ let res_body_bytes = match self . get_grpc_call_response_body ( 0 , resp_size) {
159
+ Some ( bytes) => bytes,
160
+ None => {
161
+ warn ! ( "grpc response body is empty!" ) ;
162
+ self . handle_error_on_grpc_response ( failure_mode) ;
163
+ return ;
164
+ }
165
+ } ;
170
166
let res = match GrpcMessageResponse :: new (
171
167
operation. get_extension_type ( ) ,
172
168
& res_body_bytes,
@@ -177,19 +173,19 @@ impl Context for Filter {
177
173
warn ! (
178
174
"failed to parse grpc response body into GrpcMessageResponse message: {e}"
179
175
) ;
180
- self . handle_error_on_grpc_response ( ) ;
176
+ self . handle_error_on_grpc_response ( failure_mode ) ;
181
177
return ;
182
178
}
183
179
} ;
184
180
match operation. get_extension_type ( ) {
185
- ExtensionType :: Auth => { }
186
- ExtensionType :: RateLimit => self . process_ratelimit_grpc_response ( res) ,
181
+ ExtensionType :: Auth => { } // TODO(didierofrivia): Process auth grpc response.
182
+ ExtensionType :: RateLimit => self . process_ratelimit_grpc_response ( res, failure_mode ) ,
187
183
}
188
184
189
185
self . resume_http_request ( ) ;
190
186
} else {
191
187
warn ! ( "No Operation found with token_id: {token_id}" ) ;
192
- self . handle_error_on_grpc_response ( ) ;
188
+ self . handle_error_on_grpc_response ( & FailureMode :: Deny ) ; // TODO(didierofrivia): Decide on what's the default failure mode
193
189
}
194
190
}
195
191
}
0 commit comments