use thiserror::Error;
#[derive(Error, Debug)]
#[non_exhaustive]
pub enum LnBotError {
#[error("Bad Request (400): {body}")]
BadRequest { body: String },
#[error("Unauthorized (401): {body}")]
Unauthorized { body: String },
#[error("Forbidden (403): {body}")]
Forbidden { body: String },
#[error("Not Found (404): {body}")]
NotFound { body: String },
#[error("Conflict (409): {body}")]
Conflict { body: String },
#[error("API error (HTTP {status}): {body}")]
Api { status: u16, body: String },
#[error("HTTP error: {0}")]
Http(#[from] reqwest::Error),
#[error("JSON error: {0}")]
Json(#[from] serde_json::Error),
}
pub(crate) fn from_status(status: u16, body: String) -> LnBotError {
match status {
400 => LnBotError::BadRequest { body },
401 => LnBotError::Unauthorized { body },
403 => LnBotError::Forbidden { body },
404 => LnBotError::NotFound { body },
409 => LnBotError::Conflict { body },
_ => LnBotError::Api { status, body },
}
}