#[derive(Debug, Clone, Copy, PartialEq)]
pub enum ErrorCategory {
Success,
CommonParamError,
BizParamError,
RateLimit,
TradeGlobalError,
TradePrimeError,
TradeSimulationError,
QuoteStockError,
QuoteOptionError,
QuoteFutureError,
TokenError,
PermissionError,
ServerError,
UnknownError,
}
pub fn classify_error_code(code: i32) -> ErrorCategory {
match code {
0 => ErrorCategory::Success,
5 => ErrorCategory::RateLimit,
c if (1000..1010).contains(&c) => ErrorCategory::CommonParamError,
c if (1010..1100).contains(&c) => ErrorCategory::BizParamError,
c if (1100..1200).contains(&c) => ErrorCategory::TradeGlobalError,
c if (1200..1300).contains(&c) => ErrorCategory::TradePrimeError,
c if (1300..2100).contains(&c) => ErrorCategory::TradeSimulationError,
c if (2100..2200).contains(&c) => ErrorCategory::QuoteStockError,
c if (2200..2300).contains(&c) => ErrorCategory::QuoteOptionError,
c if (2300..2400).contains(&c) => ErrorCategory::QuoteFutureError,
c if (2400..4000).contains(&c) => ErrorCategory::TokenError,
c if (4000..5000).contains(&c) => ErrorCategory::PermissionError,
_ => ErrorCategory::UnknownError,
}
}
#[cfg(test)]
mod tests;