webgates_core/errors.rs
1//! Shared crate-local error surface for `webgates-core`.
2//!
3//! This module provides the small root error enum used by fallible helper APIs
4//! in the crate. If you need a single error type for permission validation and
5//! related core workflows, this is usually the right one to return.
6//!
7//! The broader user-facing error contracts and severity taxonomy remain in
8//! [`crate::errors_core`]. This module simply provides a focused wrapper that
9//! keeps `webgates-core` APIs explicit and framework-agnostic.
10//!
11//! # Usage
12//!
13//! Use [`enum@Error`] and [`Result`] when returning the crate's shared error type from
14//! core helpers:
15//!
16//! ```rust
17//! use webgates_core::errors::{Error, Result};
18//! use webgates_core::permissions::errors::PermissionsError;
19//!
20//! fn validate(flag: bool) -> Result<()> {
21//! if flag {
22//! Ok(())
23//! } else {
24//! Err(Error::Permissions(PermissionsError::collision(
25//! 42,
26//! vec!["read:alpha".to_string(), "read:beta".to_string()],
27//! )))
28//! }
29//! }
30//! ```
31//!
32//! [`crate::errors_core`]: crate::errors_core
33
34use thiserror::Error;
35
36use crate::errors_core::{ErrorSeverity, UserFriendlyError};
37use crate::permissions::errors::PermissionsError;
38
39/// Result alias using [`enum@Error`] as the crate-local error type.
40pub type Result<T> = std::result::Result<T, Error>;
41
42/// Root error enum for `webgates-core`.
43///
44/// This enum keeps the public error surface small while still letting callers
45/// pattern match on meaningful failure categories.
46#[derive(Debug, Error)]
47pub enum Error {
48 /// Permission validation and collision errors.
49 #[error(transparent)]
50 Permissions(#[from] PermissionsError),
51}
52
53impl UserFriendlyError for Error {
54 fn user_message(&self) -> String {
55 match self {
56 Error::Permissions(err) => err.user_message(),
57 }
58 }
59
60 fn developer_message(&self) -> String {
61 match self {
62 Error::Permissions(err) => err.developer_message(),
63 }
64 }
65
66 fn support_code(&self) -> String {
67 match self {
68 Error::Permissions(err) => err.support_code(),
69 }
70 }
71
72 fn severity(&self) -> ErrorSeverity {
73 match self {
74 Error::Permissions(err) => err.severity(),
75 }
76 }
77
78 fn suggested_actions(&self) -> Vec<String> {
79 match self {
80 Error::Permissions(err) => err.suggested_actions(),
81 }
82 }
83
84 fn is_retryable(&self) -> bool {
85 match self {
86 Error::Permissions(err) => err.is_retryable(),
87 }
88 }
89}