pub enum GhostError {
Api {
message: String,
error_type: String,
context: Option<String>,
},
Http(Error),
Json(Error),
Auth(String),
}Expand description
The error type for Ghost API operations.
This enum represents all possible errors that can occur when interacting with the Ghost API, including network errors, serialization errors, API errors, and authentication errors.
Variants§
Api
An error returned by the Ghost API.
Ghost returns structured JSON errors with a message, error type, and optional context information.
Fields
Http(Error)
An HTTP error from the underlying HTTP client.
This includes network errors, connection timeouts, DNS resolution failures, and HTTP status code errors.
Json(Error)
A JSON serialization or deserialization error.
This occurs when the response from Ghost cannot be parsed or when a request body cannot be serialized.
Auth(String)
An authentication error.
This includes JWT generation failures, invalid API keys, or other authentication-related issues.
Implementations§
Source§impl GhostError
impl GhostError
Sourcepub fn api(
message: impl Into<String>,
error_type: impl Into<String>,
context: Option<String>,
) -> Self
pub fn api( message: impl Into<String>, error_type: impl Into<String>, context: Option<String>, ) -> Self
Creates a new API error with the given message and error type.
§Examples
use ghost_io_api::error::GhostError;
let error = GhostError::api(
"Resource not found",
"NotFoundError",
None,
);Sourcepub fn auth(message: impl Into<String>) -> Self
pub fn auth(message: impl Into<String>) -> Self
Creates a new authentication error.
§Examples
use ghost_io_api::error::GhostError;
let error = GhostError::auth("Invalid API key");Sourcepub fn is_api_error(&self) -> bool
pub fn is_api_error(&self) -> bool
Returns true if this is an API error.
§Examples
use ghost_io_api::error::GhostError;
let error = GhostError::api("Not found", "NotFoundError", None);
assert!(error.is_api_error());Sourcepub fn is_http_error(&self) -> bool
pub fn is_http_error(&self) -> bool
Returns true if this is an HTTP error.
Sourcepub fn is_json_error(&self) -> bool
pub fn is_json_error(&self) -> bool
Returns true if this is a JSON serialization error.
Sourcepub fn is_auth_error(&self) -> bool
pub fn is_auth_error(&self) -> bool
Returns true if this is an authentication error.
Sourcepub fn api_error_type(&self) -> Option<&str>
pub fn api_error_type(&self) -> Option<&str>
Returns the error type for API errors.
Returns None for non-API errors.
§Examples
use ghost_io_api::error::GhostError;
let error = GhostError::api("Not found", "NotFoundError", None);
assert_eq!(error.api_error_type(), Some("NotFoundError"));Sourcepub fn api_message(&self) -> Option<&str>
pub fn api_message(&self) -> Option<&str>
Returns the error message for API errors.
Returns None for non-API errors.
Sourcepub fn api_context(&self) -> Option<&str>
pub fn api_context(&self) -> Option<&str>
Returns the context for API errors.
Returns None for non-API errors or if no context is available.
Trait Implementations§
Source§impl Debug for GhostError
impl Debug for GhostError
Source§impl Display for GhostError
impl Display for GhostError
Source§impl Error for GhostError
impl Error for GhostError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()