use thiserror::Error;
use url::Url;
use crate::catalog::service_authority::ServiceAuthorityError;
use crate::types::api_version::{ApiVersion, ApiVersionError};
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum CatalogError {
#[error("Cannot parse Api Version: {}", source)]
ApiVersion {
#[from]
source: ApiVersionError,
},
#[error("Regex parse error: {}", source)]
Regex {
#[from]
source: regex::Error,
},
#[error("Url `{0}` cannot be base. [https://gtema.github.io/openstack/possible_errors.html#version-url-cannot-be-a-base]")]
UrlCannotBeBase(String),
#[error("Failed to parse url: `{}`", source)]
UrlParse {
source: url::ParseError,
url: String,
},
#[error("Failed to parse url: `{}`", source)]
UrlParseError {
#[from]
source: url::ParseError,
},
#[error("Url must be http/https")]
UrlScheme(String),
#[error("Service Authority data cannot be parsed: {}", source)]
ServiceAuthority {
#[from]
source: ServiceAuthorityError,
},
#[error("Invalid version discovery document")]
InvalidDiscoveryDocument,
#[error("Service `{0}` is not configured")]
ServiceNotConfigured(String),
#[error("Api Version with id `{id}` for service is not defining `self` link")]
VersionSelfLinkMissing { id: String },
#[error(
"Requested/Required Api Version `{}` is not supported by the server side",
ver
)]
VersionUnsupported { ver: ApiVersion },
}
impl CatalogError {
pub fn url_parse<S: AsRef<str>>(source: url::ParseError, url: S) -> Self {
Self::UrlParse {
source,
url: url.as_ref().into(),
}
}
pub fn cannot_be_base(url: &Url) -> Self {
Self::UrlCannotBeBase(url.as_str().into())
}
}