1pub mod client;
2pub mod types;
3
4pub use client::JiraClient;
5pub use types::*;
6
7use std::fmt;
8
9#[derive(Debug, Clone, PartialEq, Default)]
14pub enum AuthType {
15 #[default]
16 Basic,
17 Pat,
18}
19
20#[derive(Debug)]
21pub enum ApiError {
22 Auth(String),
24 NotFound(String),
26 InvalidInput(String),
28 RateLimit,
30 Api { status: u16, message: String },
32 Http(reqwest::Error),
34 Other(String),
36}
37
38impl fmt::Display for ApiError {
39 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40 match self {
41 ApiError::Auth(msg) => write!(
42 f,
43 "Authentication failed: {msg}\nCheck JIRA_TOKEN or run `jira config show` to verify credentials."
44 ),
45 ApiError::NotFound(msg) => write!(f, "Not found: {msg}"),
46 ApiError::InvalidInput(msg) => write!(f, "Invalid input: {msg}"),
47 ApiError::RateLimit => write!(f, "Rate limited by Jira. Please wait and try again."),
48 ApiError::Api { status, message } => write!(f, "API error {status}: {message}"),
49 ApiError::Http(e) => write!(f, "HTTP error: {e}"),
50 ApiError::Other(msg) => write!(f, "{msg}"),
51 }
52 }
53}
54
55impl std::error::Error for ApiError {
56 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
57 match self {
58 ApiError::Http(e) => Some(e),
59 _ => None,
60 }
61 }
62}
63
64impl From<reqwest::Error> for ApiError {
65 fn from(e: reqwest::Error) -> Self {
66 ApiError::Http(e)
67 }
68}