Skip to main content

orion_error/core/
reason.rs

1/// Legacy numeric error code.
2///
3/// New protocol-facing code should use the stable identity generated by
4/// `OrionError` (`identity = "biz.xxx"`, `category = ...`) as the machine key.
5/// This trait remains for compatibility with older numeric-code integrations
6/// and built-in `UvsReason` helpers.
7pub trait ErrorCode {
8    fn error_code(&self) -> i32 {
9        500
10    }
11}
12
13#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
15pub enum ErrorCategory {
16    Conf,
17    Biz,
18    Logic,
19    Sys,
20}
21
22impl ErrorCategory {
23    pub fn as_str(self) -> &'static str {
24        match self {
25            Self::Conf => "conf",
26            Self::Biz => "biz",
27            Self::Logic => "logic",
28            Self::Sys => "sys",
29        }
30    }
31}
32
33pub trait ErrorIdentityProvider {
34    fn stable_code(&self) -> &'static str;
35
36    fn error_category(&self) -> ErrorCategory;
37}