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(
15    feature = "serde",
16    derive(serde::Serialize, serde::Deserialize),
17    serde(rename_all = "lowercase")
18)]
19pub enum ErrorCategory {
20    Conf,
21    Biz,
22    Logic,
23    Sys,
24}
25
26impl ErrorCategory {
27    pub fn as_str(self) -> &'static str {
28        match self {
29            Self::Conf => "conf",
30            Self::Biz => "biz",
31            Self::Logic => "logic",
32            Self::Sys => "sys",
33        }
34    }
35}
36
37pub trait ErrorIdentityProvider {
38    fn stable_code(&self) -> &'static str;
39
40    fn error_category(&self) -> ErrorCategory;
41}