use crate::transport::TransportError;
type BoxError = Box<dyn std::error::Error + Send + Sync>;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("transport error: {0}")]
Transport(#[from] TransportError),
#[error("failed to encode request: {0}")]
Encode(#[source] BoxError),
#[error("failed to decode response: {0}")]
Decode(#[source] BoxError),
#[error("OKX API error {code}: {message}")]
Api {
code: String,
message: String,
},
#[error("HTTP status {status}: {body}")]
HttpStatus {
status: http::StatusCode,
body: String,
},
#[error("invalid configuration: {0}")]
Configuration(String),
}
impl Error {
pub(crate) fn encode(err: impl Into<BoxError>) -> Self {
Error::Encode(err.into())
}
pub(crate) fn decode(err: impl Into<BoxError>) -> Self {
Error::Decode(err.into())
}
}