Skip to content

Commit f263481

Browse files
committed
fix: map group route operation errors
1 parent a9f6f5d commit f263481

1 file changed

Lines changed: 26 additions & 5 deletions

File tree

api/src/routes/groups.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ use aruna_core::structs::{
66
Actor, AuthContext, Group, GroupAuthorizationDocument, Permission, Role,
77
};
88
use aruna_core::types::RoleId;
9-
use aruna_operations::add_group_role::{AddGroupRoleConfig, AddGroupRoleOperation};
9+
use aruna_operations::add_group_role::{
10+
AddGroupRoleConfig, AddGroupRoleError, AddGroupRoleOperation,
11+
};
1012
use aruna_operations::add_user_to_group::{
1113
AddUserToGroupError, AddUserToGroupInput, AddUserToGroupOperation,
1214
};
1315
use aruna_operations::check_permissions::{CheckPermissionsConfig, CheckPermissionsOperation};
1416
use aruna_operations::create_group::{CreateGroupConfig, CreateGroupOperation};
1517
use aruna_operations::driver::drive;
16-
use aruna_operations::get_group::{GetGroupConfig, GetGroupOperation};
18+
use aruna_operations::get_group::{GetGroupConfig, GetGroupError, GetGroupOperation};
1719
use aruna_operations::list_groups::ListGroupOperation;
1820
use aruna_operations::remove_group_role::{
1921
RemoveGroupRoleConfig, RemoveGroupRoleError, RemoveGroupRoleOperation,
@@ -269,7 +271,14 @@ async fn load_group(
269271
&state.get_ctx(),
270272
)
271273
.await
272-
.map_err(|err| ServerError::InternalError(err.to_string()))
274+
.map_err(map_get_group_error)
275+
}
276+
277+
fn map_get_group_error(error: GetGroupError) -> ServerError {
278+
match error {
279+
GetGroupError::GroupNotFound | GetGroupError::AuthDocNotFound => ServerError::NotFound,
280+
other => ServerError::InternalError(other.to_string()),
281+
}
273282
}
274283

275284
impl From<(Group, GroupAuthorizationDocument)> for CreateGroupResponse {
@@ -514,6 +523,17 @@ fn map_add_member_error(error: AddUserToGroupError) -> ServerError {
514523
}
515524
}
516525

526+
fn map_add_role_error(error: AddGroupRoleError) -> ServerError {
527+
match error {
528+
AddGroupRoleError::Unauthorized => ServerError::Forbidden,
529+
AddGroupRoleError::GroupNotFound => ServerError::NotFound,
530+
AddGroupRoleError::CheckPermissionsError(
531+
AuthorizationError::GroupNotFound | AuthorizationError::AuthDocNotFound,
532+
) => ServerError::NotFound,
533+
other => ServerError::InternalError(other.to_string()),
534+
}
535+
}
536+
517537
fn map_remove_member_error(error: RemoveUserFromGroupError) -> ServerError {
518538
match error {
519539
RemoveUserFromGroupError::Unauthorized => ServerError::Forbidden,
@@ -731,7 +751,8 @@ pub async fn leave_group(
731751
(status = 201, description = "Role created", body = RoleResponse),
732752
(status = 400, description = "Invalid request or foreign permission path", body = ErrorResponse),
733753
(status = 401, description = "Unauthorized", body = ErrorResponse),
734-
(status = 403, description = "Forbidden", body = ErrorResponse)
754+
(status = 403, description = "Forbidden", body = ErrorResponse),
755+
(status = 404, description = "Group not found", body = ErrorResponse)
735756
),
736757
security(("bearer_auth" = []))
737758
)]
@@ -790,7 +811,7 @@ pub async fn create_group_role(
790811
&state.get_ctx(),
791812
)
792813
.await
793-
.map_err(|err| ServerError::InternalError(err.to_string()))?;
814+
.map_err(map_add_role_error)?;
794815

795816
let role = map_roles(auth_doc)
796817
.into_iter()

0 commit comments

Comments
 (0)