52
52
53
53
fn call ( & self , req : ServiceRequest ) -> Self :: Future {
54
54
let query_string = req. query_string ( ) ;
55
+ let method = req. method ( ) ;
56
+ let path = req. path ( ) ;
57
+ let request_info = format ! ( "{method} {path}?{query_string}" ) ;
55
58
let query: Result < web:: Query < RepoQuery > , _ > = web:: Query :: from_query ( query_string) ;
56
59
let RepoQuery {
57
60
owner,
@@ -60,12 +63,15 @@ where
60
63
} = match query {
61
64
Ok ( q) => q. into_inner ( ) ,
62
65
Err ( e) => {
63
- println ! ( "{e}" ) ;
64
- return Box :: pin ( async {
65
- Err ( actix_web:: error:: ErrorBadRequest (
66
- "Wrong query string format" ,
67
- ) )
68
- } ) ;
66
+ let err = actix_web:: error:: ErrorBadRequest ( format ! (
67
+ "Wrong query string format error: {e}"
68
+ ) ) ;
69
+ log:: info!(
70
+ "{} {}" ,
71
+ request_info,
72
+ err. as_response_error( ) . status_code( ) . as_u16( )
73
+ ) ;
74
+ return Box :: pin ( async { Err ( err) } ) ;
69
75
}
70
76
} ;
71
77
@@ -89,36 +95,71 @@ where
89
95
. header ( "User-Agent" , "Actix-web" )
90
96
. send ( )
91
97
. await
92
- . map_err ( actix_web:: error:: ErrorBadRequest ) ?;
98
+ . map_err ( |e| {
99
+ let err = actix_web:: error:: ErrorBadRequest ( e) ;
100
+ log:: info!(
101
+ "{} {}" ,
102
+ request_info,
103
+ err. as_response_error( ) . status_code( ) . as_u16( )
104
+ ) ;
105
+ err
106
+ } ) ?;
93
107
94
108
if user_info_result. status ( ) . is_success ( ) {
95
- let user_info = user_info_result
96
- . json :: < serde_json:: Value > ( )
97
- . await
98
- . expect ( "Failed to parse JSON" ) ;
109
+ let user_info =
110
+ user_info_result
111
+ . json :: < serde_json:: Value > ( )
112
+ . await
113
+ . map_err ( |_| {
114
+ let err = actix_web:: error:: ErrorInternalServerError (
115
+ "GitHub handle information not found." ,
116
+ ) ;
117
+ log:: info!(
118
+ "{} {}" ,
119
+ request_info,
120
+ err. as_response_error( ) . status_code( ) . as_u16( )
121
+ ) ;
122
+ log:: error!( "{err}" ) ;
123
+ err
124
+ } ) ?;
99
125
100
126
if let Some ( login) = user_info. get ( "login" ) . and_then ( |v| v. as_str ( ) ) {
101
127
user_handle = login. to_string ( ) ;
102
128
} else {
103
- println ! ( "GitHub handle information not found." ) ;
104
- return Err ( actix_web:: error:: ErrorInternalServerError (
129
+ let err = actix_web:: error:: ErrorInternalServerError (
105
130
"GitHub handle information not found." ,
106
- ) ) ;
131
+ ) ;
132
+ log:: info!(
133
+ "{} {}" ,
134
+ request_info,
135
+ err. as_response_error( ) . status_code( ) . as_u16( )
136
+ ) ;
137
+ log:: error!( "{err}" ) ;
138
+ return Err ( err) ;
107
139
}
108
140
} else {
109
- println ! ( "Failed to get GitHub user info" ) ;
110
- return Err ( actix_web:: error:: ErrorUnauthorized (
111
- "Failed to get GitHub user info." ,
112
- ) ) ;
141
+ let err = actix_web:: error:: ErrorUnauthorized ( "Failed to get GitHub user info" ) ;
142
+ log:: info!(
143
+ "{} {}" ,
144
+ request_info,
145
+ err. as_response_error( ) . status_code( ) . as_u16( )
146
+ ) ;
147
+ log:: error!( "{err}" ) ;
148
+ return Err ( err) ;
113
149
}
114
150
}
115
151
116
152
if github_username != user_handle {
117
- // comment this for testing
118
- println ! ( "Sent GitHub handle different than auth token owner." ) ;
119
- return Err ( actix_web:: error:: ErrorBadRequest (
153
+ let err = actix_web:: error:: ErrorUnauthorized (
120
154
"Sent GitHub handle different than auth token owner." ,
121
- ) ) ;
155
+ ) ;
156
+ log:: info!(
157
+ "{} {}" ,
158
+ request_info,
159
+ err. as_response_error( ) . status_code( ) . as_u16( )
160
+ ) ;
161
+ log:: error!( "{err}" ) ;
162
+ return Err ( err) ;
122
163
}
123
164
124
165
match get_allocator ( & owner, & repo) . await {
@@ -130,18 +171,31 @@ where
130
171
. map ( |s| s. trim ( ) . to_lowercase ( ) )
131
172
. collect ( ) ;
132
173
if verifier_handles. contains ( & user_handle. to_lowercase ( ) ) {
133
- println ! ( "{user_handle} is a verifier." ) ;
174
+ log :: info !( "{user_handle} is a verifier." ) ;
134
175
} else {
135
- println ! ( "The user is not a verifier." ) ;
136
- return Err ( actix_web:: error:: ErrorUnauthorized (
176
+ let err = actix_web:: error:: ErrorUnauthorized (
137
177
"The user is not a verifier." ,
138
- ) ) ;
178
+ ) ;
179
+ log:: info!(
180
+ "{} {}" ,
181
+ request_info,
182
+ err. as_response_error( ) . status_code( ) . as_u16( )
183
+ ) ;
184
+ log:: error!( "{err}" ) ;
185
+ return Err ( err) ;
139
186
}
140
187
}
141
188
}
142
189
}
143
190
Err ( e) => {
144
- println ! ( "Failed to get allocator: {e:?}" ) ;
191
+ let err = actix_web:: error:: ErrorInternalServerError ( e) ;
192
+ log:: info!(
193
+ "{} {}" ,
194
+ request_info,
195
+ err. as_response_error( ) . status_code( ) . as_u16( )
196
+ ) ;
197
+ log:: error!( "{err}" ) ;
198
+ return Err ( err) ;
145
199
}
146
200
}
147
201
0 commit comments