use derive_builder::UninitializedFieldError;
use serde::Deserialize;
use std::fmt;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Deserialize)]
pub struct BraviaErrorCode {
pub code: usize,
pub message: String,
}
impl fmt::Display for BraviaErrorCode {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "#{}: {}", self.code, self.message)
}
}
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("An error occurred during initialization")]
FieldInitialization(#[from] UninitializedFieldError),
#[error("NetworkError: {}", _0)]
NetworkError(#[from] reqwest::Error),
#[error("Error status received: {}", _0)]
BadStatus(reqwest::StatusCode),
#[error("Value missing from response: {}", _0)]
MissingValue(&'static str),
#[error("Invalid response received: {}", _0)]
InvalidResponse(&'static str),
#[error("JSON deserialize error: {}", _0)]
DeserializeError(#[from] serde_json::Error),
#[error("Error returned by Bravia: {}", _0)]
BraviaError(BraviaErrorCode),
#[error("API service not found.")]
BraviaApiServiceNotFound,
#[error("API not found.")]
BraviaApiNotFound,
#[error("This API version is not supported.")]
BraviaApiLevelError,
#[error("A password is required in order to access this API")]
BraviaAuthLevelError,
}