Commit 1cecc59 1 parent b5da547 commit 1cecc59 Copy full SHA for 1cecc59
File tree 2 files changed +6
-2
lines changed
2 files changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -148,6 +148,9 @@ pub enum ServiceError {
148
148
#[ display( fmt = "Database error." ) ]
149
149
DatabaseError ,
150
150
151
+ #[ display( fmt = "You must be logged in!." ) ]
152
+ LoggedInUserNotFound ,
153
+
151
154
// Begin tracker errors
152
155
#[ display( fmt = "Sorry, we have an error with our tracker connection." ) ]
153
156
TrackerOffline ,
@@ -311,6 +314,7 @@ pub fn http_status_code_for_service_error(error: &ServiceError) -> StatusCode {
311
314
ServiceError :: TrackerUnknownResponse => StatusCode :: INTERNAL_SERVER_ERROR ,
312
315
ServiceError :: TorrentNotFoundInTracker => StatusCode :: NOT_FOUND ,
313
316
ServiceError :: InvalidTrackerToken => StatusCode :: INTERNAL_SERVER_ERROR ,
317
+ ServiceError :: LoggedInUserNotFound => StatusCode :: UNAUTHORIZED ,
314
318
}
315
319
}
316
320
Original file line number Diff line number Diff line change @@ -23,15 +23,15 @@ where
23
23
async fn from_request_parts ( parts : & mut Parts , state : & S ) -> Result < Self , Self :: Rejection > {
24
24
let maybe_bearer_token = match bearer_token:: Extract :: from_request_parts ( parts, state) . await {
25
25
Ok ( maybe_bearer_token) => maybe_bearer_token. 0 ,
26
- Err ( _) => return Err ( ServiceError :: Unauthorized . into_response ( ) ) ,
26
+ Err ( _) => return Err ( ServiceError :: TokenNotFound . into_response ( ) ) ,
27
27
} ;
28
28
29
29
//Extracts the app state
30
30
let app_data = Arc :: from_ref ( state) ;
31
31
32
32
match app_data. auth . get_user_id_from_bearer_token ( & maybe_bearer_token) . await {
33
33
Ok ( user_id) => Ok ( ExtractLoggedInUser ( user_id) ) ,
34
- Err ( _) => Err ( ServiceError :: Unauthorized . into_response ( ) ) ,
34
+ Err ( _) => Err ( ServiceError :: LoggedInUserNotFound . into_response ( ) ) ,
35
35
}
36
36
}
37
37
}
You can’t perform that action at this time.
0 commit comments