Skip to main content

mini_chat_sdk/
error.rs

1use thiserror::Error;
2
3/// Errors returned by `MiniChatModelPolicyPluginClientV1` methods.
4#[derive(Debug, Error)]
5pub enum MiniChatModelPolicyPluginError {
6    #[error("policy not found for the given tenant/version")]
7    NotFound,
8
9    #[error("internal policy plugin error: {0}")]
10    Internal(String),
11}
12
13/// Errors returned by `MiniChatAuditPluginClientV1` methods.
14///
15/// Mirrors `PublishError` transient/permanent classification so callers can
16/// decide whether to retry or record the failure as permanent.
17#[derive(Debug, Error)]
18pub enum MiniChatAuditPluginError {
19    /// Transient failure — safe to retry (network timeout, broker unavailable).
20    #[error("transient audit plugin error: {0}")]
21    Transient(String),
22
23    /// Permanent failure — do not retry (schema mismatch, auth rejected).
24    #[error("permanent audit plugin error: {0}")]
25    Permanent(String),
26}
27
28impl MiniChatAuditPluginError {
29    #[must_use]
30    pub fn is_transient(&self) -> bool {
31        matches!(self, Self::Transient(_))
32    }
33
34    #[must_use]
35    pub fn is_permanent(&self) -> bool {
36        matches!(self, Self::Permanent(_))
37    }
38}
39
40/// Errors returned by `publish_usage()`.
41#[derive(Debug, Error)]
42pub enum PublishError {
43    /// Transient failure — safe to retry.
44    #[error("transient publish error: {0}")]
45    Transient(String),
46
47    /// Permanent failure — do not retry.
48    #[error("permanent publish error: {0}")]
49    Permanent(String),
50}
51
52impl PublishError {
53    #[must_use]
54    pub fn is_transient(&self) -> bool {
55        matches!(self, Self::Transient(_))
56    }
57
58    #[must_use]
59    pub fn is_permanent(&self) -> bool {
60        matches!(self, Self::Permanent(_))
61    }
62}