use crate::errors::AuthError; pub(crate) fn reason_error(reason: &'static str, permission: &str) -> AuthError { match reason { "org_inactive" => AuthError::OrganizationInactive, "member_banned" => AuthError::OrganizationMemberBanned, "not_member" | "member_left" => AuthError::Forbidden, _ => AuthError::ScopeInsufficient { required: permission.to_owned(), }, } } pub(crate) fn map_insert_conflict(error: sea_orm::DbErr) -> AuthError { if let sea_orm::DbErr::Query(sea_orm::RuntimeErr::SqlxError(source)) = &error && let Some(code) = source.as_database_error().and_then(|db| db.code()) && code.as_ref() == "23505" { return AuthError::OrganizationSlugTaken; } AuthError::from(error) }