Skip to content

Commit

Permalink
torrust#72: Specific error code added
Browse files Browse the repository at this point in the history
  • Loading branch information
alexohneander committed Jul 31, 2023
1 parent 946ea97 commit a15af48
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ pub enum ServiceError {
#[display(fmt = "Only .torrent files can be uploaded.")]
InvalidFileType,

#[display(fmt = "Torrent title is too short.")]
InvalidTorrentTitleLength,

#[display(fmt = "Bad request.")]
BadRequest,

Expand Down Expand Up @@ -219,6 +222,7 @@ pub fn http_status_code_for_service_error(error: &ServiceError) -> StatusCode {
ServiceError::InvalidTorrentFile => StatusCode::BAD_REQUEST,
ServiceError::InvalidTorrentPiecesLength => StatusCode::BAD_REQUEST,
ServiceError::InvalidFileType => StatusCode::BAD_REQUEST,
&ServiceError::InvalidTorrentTitleLength => StatusCode::BAD_REQUEST,
ServiceError::BadRequest => StatusCode::BAD_REQUEST,
ServiceError::InvalidCategory => StatusCode::BAD_REQUEST,
ServiceError::InvalidTag => StatusCode::BAD_REQUEST,
Expand Down
2 changes: 1 addition & 1 deletion src/services/torrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl Index {
torrent_request.torrent.set_announce_urls(&self.configuration).await;

if torrent_request.metadata.title.len() < 3 {
return Err(ServiceError::BadRequest);
return Err(ServiceError::InvalidTorrentTitleLength);
}

let category = self
Expand Down

0 comments on commit a15af48

Please sign in to comment.