axum_gate/permissions/
errors.rs1use crate::errors::{ErrorSeverity, UserFriendlyError};
24use thiserror::Error;
25
26#[derive(Debug, Error)]
31#[non_exhaustive]
32pub enum PermissionsError {
33 #[error("Permission collision: {collision_count} permissions map to hash {hash_id}")]
35 Collision {
36 collision_count: usize,
38 hash_id: u64,
40 permissions: Vec<String>,
42 },
43}
44
45impl PermissionsError {
46 pub fn collision(hash_id: u64, permissions: Vec<String>) -> Self {
50 PermissionsError::Collision {
51 collision_count: permissions.len(),
52 hash_id,
53 permissions,
54 }
55 }
56
57 fn support_code_inner(&self) -> String {
59 match self {
60 PermissionsError::Collision { hash_id, .. } => {
61 format!("PERM-COLLISION-{}", hash_id)
62 }
63 }
64 }
65}
66
67impl UserFriendlyError for PermissionsError {
68 fn user_message(&self) -> String {
69 match self {
70 PermissionsError::Collision { .. } => {
71 "There's a technical issue with your account permissions. Our support team has been notified and will resolve this shortly. Please contact support if you need immediate assistance.".to_string()
72 }
73 }
74 }
75
76 fn developer_message(&self) -> String {
77 match self {
78 PermissionsError::Collision {
79 collision_count,
80 hash_id,
81 permissions,
82 } => {
83 format!(
84 "Permission collision detected: {} permissions [{}] map to hash ID {}. This indicates a critical hash collision in the permission system requiring immediate administrator attention.",
85 collision_count,
86 permissions.join(", "),
87 hash_id
88 )
89 }
90 }
91 }
92
93 fn support_code(&self) -> String {
94 self.support_code_inner()
95 }
96
97 fn severity(&self) -> ErrorSeverity {
98 match self {
99 PermissionsError::Collision { .. } => ErrorSeverity::Critical,
100 }
101 }
102
103 fn suggested_actions(&self) -> Vec<String> {
104 match self {
105 PermissionsError::Collision { .. } => vec![
106 "Contact our support team immediately with the reference code below".to_string(),
107 "Do not attempt to retry this operation".to_string(),
108 "This is a critical system issue requiring immediate administrator attention"
109 .to_string(),
110 ],
111 }
112 }
113
114 fn is_retryable(&self) -> bool {
115 match self {
116 PermissionsError::Collision { .. } => false, }
118 }
119}