Skip to content

Commit 42fb031

Browse files
committed
refactor: [#615] renamed error to be more human friendly
1 parent 836c94d commit 42fb031

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ pub enum ServiceError {
109109
InvalidTag,
110110

111111
#[display(fmt = "Unauthorized action.")]
112-
Unauthorized,
112+
UnauthorizedAction,
113113

114114
#[display(fmt = "This torrent already exists in our database.")]
115115
InfoHashAlreadyExists,
@@ -300,7 +300,7 @@ pub fn http_status_code_for_service_error(error: &ServiceError) -> StatusCode {
300300
ServiceError::MissingMandatoryMetadataFields => StatusCode::BAD_REQUEST,
301301
ServiceError::InvalidCategory => StatusCode::BAD_REQUEST,
302302
ServiceError::InvalidTag => StatusCode::BAD_REQUEST,
303-
ServiceError::Unauthorized => StatusCode::FORBIDDEN,
303+
ServiceError::UnauthorizedAction => StatusCode::FORBIDDEN,
304304
ServiceError::InfoHashAlreadyExists => StatusCode::BAD_REQUEST,
305305
ServiceError::CanonicalInfoHashAlreadyExists => StatusCode::CONFLICT,
306306
ServiceError::OriginalInfoHashAlreadyExists => StatusCode::CONFLICT,

src/services/authorization.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,14 @@ impl Service {
7979

8080
let enforcer = self.casbin_enforcer.enforcer.read().await;
8181

82-
let authorize = enforcer.enforce((role, action)).map_err(|_| ServiceError::Unauthorized)?;
82+
let authorize = enforcer
83+
.enforce((role, action))
84+
.map_err(|_| ServiceError::UnauthorizedAction)?;
8385

8486
if authorize {
8587
Ok(())
8688
} else {
87-
Err(ServiceError::Unauthorized)
89+
Err(ServiceError::UnauthorizedAction)
8890
}
8991
}
9092

src/services/torrent.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ impl Index {
433433
// Check if user is owner or administrator
434434
// todo: move this to an authorization service.
435435
if !(torrent_listing.uploader == updater.username || updater.administrator) {
436-
return Err(ServiceError::Unauthorized);
436+
return Err(ServiceError::UnauthorizedAction);
437437
}
438438

439439
self.torrent_info_repository

0 commit comments

Comments
 (0)