Skip to content

Commit 70ac664

Browse files
committed
fix: [#420] proper handling for tracker API responses
Some cases were missing when the tracker service processes the responses from the tracker API. Added debugging and error log. todo: add tests
1 parent 7620ed1 commit 70ac664

File tree

2 files changed

+162
-157
lines changed

2 files changed

+162
-157
lines changed

src/errors.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ pub enum ServiceError {
148148
#[display(fmt = "Database error.")]
149149
DatabaseError,
150150

151-
// Tracker errors
151+
// Begin tracker errors
152152
#[display(fmt = "Sorry, we have an error with our tracker connection.")]
153153
TrackerOffline,
154154

@@ -160,6 +160,10 @@ pub enum ServiceError {
160160

161161
#[display(fmt = "Torrent not found in tracker.")]
162162
TorrentNotFoundInTracker,
163+
164+
#[display(fmt = "Invalid tracker API token.")]
165+
InvalidTrackerToken,
166+
// End tracker errors
163167
}
164168

165169
impl From<sqlx::Error> for ServiceError {
@@ -244,14 +248,13 @@ impl From<TrackerAPIError> for ServiceError {
244248
eprintln!("{e}");
245249
match e {
246250
TrackerAPIError::TrackerOffline => ServiceError::TrackerOffline,
247-
TrackerAPIError::AddToWhitelistError
248-
| TrackerAPIError::RemoveFromWhitelistError
249-
| TrackerAPIError::RetrieveUserKeyError => ServiceError::TrackerResponseError,
251+
TrackerAPIError::InternalServerError => ServiceError::TrackerResponseError,
250252
TrackerAPIError::TorrentNotFound => ServiceError::TorrentNotFoundInTracker,
251-
TrackerAPIError::MissingResponseBody | TrackerAPIError::FailedToParseTrackerResponse { body: _ } => {
252-
ServiceError::TrackerUnknownResponse
253-
}
253+
TrackerAPIError::UnexpectedResponseStatus
254+
| TrackerAPIError::MissingResponseBody
255+
| TrackerAPIError::FailedToParseTrackerResponse { body: _ } => ServiceError::TrackerUnknownResponse,
254256
TrackerAPIError::CannotSaveUserKey => ServiceError::DatabaseError,
257+
TrackerAPIError::InvalidToken => ServiceError::InvalidTrackerToken,
255258
}
256259
}
257260
}
@@ -307,6 +310,7 @@ pub fn http_status_code_for_service_error(error: &ServiceError) -> StatusCode {
307310
ServiceError::TrackerResponseError => StatusCode::INTERNAL_SERVER_ERROR,
308311
ServiceError::TrackerUnknownResponse => StatusCode::INTERNAL_SERVER_ERROR,
309312
ServiceError::TorrentNotFoundInTracker => StatusCode::NOT_FOUND,
313+
ServiceError::InvalidTrackerToken => StatusCode::INTERNAL_SERVER_ERROR,
310314
}
311315
}
312316

0 commit comments

Comments
 (0)