@@ -13,23 +13,29 @@ use crate::{header, types::*};
13
13
use crate :: { apis, models} ;
14
14
15
15
/// Setup API Server.
16
- pub fn new < I , A , C > ( api_impl : I ) -> Router
16
+ pub fn new < I , A , E , C > ( api_impl : I ) -> Router
17
17
where
18
18
I : AsRef < A > + Clone + Send + Sync + ' static ,
19
- A : apis:: payments:: Payments < Claims = C >
19
+ A : apis:: payments:: Payments < E , Claims = C >
20
20
+ apis:: ApiKeyAuthHeader < Claims = C >
21
21
+ apis:: CookieAuthentication < Claims = C >
22
+ + Send
23
+ + Sync
22
24
+ ' static ,
25
+ E : std:: fmt:: Debug + Send + Sync + ' static ,
23
26
C : Send + Sync + ' static ,
24
27
{
25
28
// build our application with a route
26
29
Router :: new ( )
27
- . route ( "/v71/paymentMethods" , get ( get_payment_methods :: < I , A , C > ) )
30
+ . route (
31
+ "/v71/paymentMethods" ,
32
+ get ( get_payment_methods :: < I , A , E , C > ) ,
33
+ )
28
34
. route (
29
35
"/v71/paymentMethods/:id" ,
30
- get ( get_payment_method_by_id :: < I , A , C > ) ,
36
+ get ( get_payment_method_by_id :: < I , A , E , C > ) ,
31
37
)
32
- . route ( "/v71/payments" , post ( post_make_payment :: < I , A , C > ) )
38
+ . route ( "/v71/payments" , post ( post_make_payment :: < I , A , E , C > ) )
33
39
. with_state ( api_impl)
34
40
}
35
41
@@ -43,7 +49,7 @@ fn get_payment_method_by_id_validation(
43
49
}
44
50
/// GetPaymentMethodById - GET /v71/paymentMethods/{id}
45
51
#[ tracing:: instrument( skip_all) ]
46
- async fn get_payment_method_by_id < I , A , C > (
52
+ async fn get_payment_method_by_id < I , A , E , C > (
47
53
method : Method ,
48
54
host : Host ,
49
55
cookies : CookieJar ,
@@ -52,7 +58,8 @@ async fn get_payment_method_by_id<I, A, C>(
52
58
) -> Result < Response , StatusCode >
53
59
where
54
60
I : AsRef < A > + Send + Sync ,
55
- A : apis:: payments:: Payments < Claims = C > ,
61
+ A : apis:: payments:: Payments < E , Claims = C > + Send + Sync ,
62
+ E : std:: fmt:: Debug + Send + Sync + ' static ,
56
63
{
57
64
#[ allow( clippy:: redundant_closure) ]
58
65
let validation =
@@ -123,10 +130,10 @@ where
123
130
response. body ( Body :: from ( body_content) )
124
131
}
125
132
} ,
126
- Err ( _ ) => {
133
+ Err ( why ) => {
127
134
// Application code returned an error. This should not happen, as the implementation should
128
135
// return a valid response.
129
- response . status ( 500 ) . body ( Body :: empty ( ) )
136
+ return api_impl . as_ref ( ) . handle_error ( why ) . await ;
130
137
}
131
138
} ;
132
139
@@ -142,15 +149,16 @@ fn get_payment_methods_validation() -> std::result::Result<(), ValidationErrors>
142
149
}
143
150
/// GetPaymentMethods - GET /v71/paymentMethods
144
151
#[ tracing:: instrument( skip_all) ]
145
- async fn get_payment_methods < I , A , C > (
152
+ async fn get_payment_methods < I , A , E , C > (
146
153
method : Method ,
147
154
host : Host ,
148
155
cookies : CookieJar ,
149
156
State ( api_impl) : State < I > ,
150
157
) -> Result < Response , StatusCode >
151
158
where
152
159
I : AsRef < A > + Send + Sync ,
153
- A : apis:: payments:: Payments < Claims = C > ,
160
+ A : apis:: payments:: Payments < E , Claims = C > + Send + Sync ,
161
+ E : std:: fmt:: Debug + Send + Sync + ' static ,
154
162
{
155
163
#[ allow( clippy:: redundant_closure) ]
156
164
let validation = tokio:: task:: spawn_blocking ( move || get_payment_methods_validation ( ) )
@@ -197,10 +205,10 @@ where
197
205
response. body ( Body :: from ( body_content) )
198
206
}
199
207
} ,
200
- Err ( _ ) => {
208
+ Err ( why ) => {
201
209
// Application code returned an error. This should not happen, as the implementation should
202
210
// return a valid response.
203
- response . status ( 500 ) . body ( Body :: empty ( ) )
211
+ return api_impl . as_ref ( ) . handle_error ( why ) . await ;
204
212
}
205
213
} ;
206
214
@@ -230,7 +238,7 @@ fn post_make_payment_validation(
230
238
}
231
239
/// PostMakePayment - POST /v71/payments
232
240
#[ tracing:: instrument( skip_all) ]
233
- async fn post_make_payment < I , A , C > (
241
+ async fn post_make_payment < I , A , E , C > (
234
242
method : Method ,
235
243
host : Host ,
236
244
cookies : CookieJar ,
@@ -239,7 +247,11 @@ async fn post_make_payment<I, A, C>(
239
247
) -> Result < Response , StatusCode >
240
248
where
241
249
I : AsRef < A > + Send + Sync ,
242
- A : apis:: payments:: Payments < Claims = C > + apis:: CookieAuthentication < Claims = C > ,
250
+ A : apis:: payments:: Payments < E , Claims = C >
251
+ + apis:: CookieAuthentication < Claims = C >
252
+ + Send
253
+ + Sync ,
254
+ E : std:: fmt:: Debug + Send + Sync + ' static ,
243
255
{
244
256
// Authentication
245
257
let claims_in_cookie = api_impl
@@ -322,10 +334,10 @@ where
322
334
response. body ( Body :: from ( body_content) )
323
335
}
324
336
} ,
325
- Err ( _ ) => {
337
+ Err ( why ) => {
326
338
// Application code returned an error. This should not happen, as the implementation should
327
339
// return a valid response.
328
- response . status ( 500 ) . body ( Body :: empty ( ) )
340
+ return api_impl . as_ref ( ) . handle_error ( why ) . await ;
329
341
}
330
342
} ;
331
343
0 commit comments