use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ErrorCode {
code: &'static str,
status: u16,
}
impl ErrorCode {
pub const SUSPENDED: Self = Self {
code: "suspended",
status: 403,
};
pub const ARCHIVE_REQUIRED: Self = Self {
code: "archive_required",
status: 409,
};
pub const POD_DATA_PRESENT: Self = Self {
code: "pod_data_present",
status: 409,
};
pub const APP_FORBIDDEN: Self = Self {
code: "app_forbidden",
status: 403,
};
pub const RATE_LIMITED: Self = Self {
code: "rate_limited",
status: 429,
};
pub const LEASE_REVOKED: Self = Self {
code: "lease_revoked",
status: 403,
};
pub const OUTSIDE_GRANT: Self = Self {
code: "outside_grant",
status: 403,
};
pub const LEASE_STARTING: Self = Self {
code: "lease_starting",
status: 503,
};
pub const LEASE_EXPIRED: Self = Self {
code: "lease_expired",
status: 503,
};
pub const BUSY: Self = Self {
code: "busy",
status: 503,
};
pub const POD_AUTH_REFUSED: Self = Self {
code: "pod_auth_refused",
status: 503,
};
pub const KEY_DISABLED: Self = Self {
code: "key_disabled",
status: 403,
};
pub const NO_WINDOW: Self = Self {
code: "no_window",
status: 403,
};
pub const OUTSIDE_POD: Self = Self {
code: "outside_pod",
status: 403,
};
pub const PAYLOAD_RULE: Self = Self {
code: "payload_rule",
status: 400,
};
pub const APPLICATION_UNAVAILABLE: Self = Self {
code: "application_unavailable",
status: 409,
};
pub const IMAGE_HAS_VOLUMES: Self = Self {
code: "image_has_volumes",
status: 409,
};
pub const IMAGE_ABSENT: Self = Self {
code: "image_absent",
status: 409,
};
pub const WORKSPACE_UNAVAILABLE: Self = Self {
code: "workspace_unavailable",
status: 409,
};
pub const CONTAINER_IDENTITY_CONFLICT: Self = Self {
code: "container_identity_conflict",
status: 409,
};
pub const CREATE_EXPIRED: Self = Self {
code: "create_expired",
status: 409,
};
pub const RUNNER_UNAVAILABLE: Self = Self {
code: "runner_unavailable",
status: 503,
};
pub const SIGNER_UNAVAILABLE: Self = Self {
code: "signer_unavailable",
status: 503,
};
pub const ALL: [Self; 23] = [
Self::SUSPENDED,
Self::ARCHIVE_REQUIRED,
Self::POD_DATA_PRESENT,
Self::APP_FORBIDDEN,
Self::RATE_LIMITED,
Self::LEASE_REVOKED,
Self::OUTSIDE_GRANT,
Self::LEASE_STARTING,
Self::LEASE_EXPIRED,
Self::BUSY,
Self::POD_AUTH_REFUSED,
Self::KEY_DISABLED,
Self::NO_WINDOW,
Self::OUTSIDE_POD,
Self::PAYLOAD_RULE,
Self::APPLICATION_UNAVAILABLE,
Self::IMAGE_HAS_VOLUMES,
Self::IMAGE_ABSENT,
Self::WORKSPACE_UNAVAILABLE,
Self::CONTAINER_IDENTITY_CONFLICT,
Self::CREATE_EXPIRED,
Self::RUNNER_UNAVAILABLE,
Self::SIGNER_UNAVAILABLE,
];
pub const fn as_str(self) -> &'static str {
self.code
}
pub const fn status(self) -> u16 {
self.status
}
pub fn from_code(code: &str) -> Option<Self> {
Self::ALL.into_iter().find(|known| known.code == code)
}
}
impl fmt::Display for ErrorCode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.code)
}
}