pub mod api;
pub mod client;
pub use api::CallOutput;
pub use client::{Credential, TencentClient};
pub use hyper;
pub use hyper_rustls;
#[derive(Debug)]
pub enum Error {
HttpError(hyper::Error),
UploadSizeLimitExceeded(u64, u64),
BadRequest(serde_json::Value),
MissingAPIKey,
Cancelled,
FieldClash(&'static str),
MissingField(&'static str),
JsonError(String, serde_json::Error),
Failure(hyper::Response<hyper::body::Body>),
Io(std::io::Error),
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match *self {
Error::Io(ref err) => err.fmt(f),
Error::HttpError(ref err) => err.fmt(f),
Error::UploadSizeLimitExceeded(ref resource_size, ref max_size) => writeln!(
f,
"The media size {} exceeds the maximum allowed upload size of {}",
resource_size, max_size
),
Error::MissingAPIKey => {
(writeln!(
f,
"The application's API key was not found in the configuration"
))
.ok();
writeln!(
f,
"It is used as there are no Scopes defined for this method."
)
}
Error::BadRequest(ref message) => {
writeln!(f, "Bad Request: {}", message)?;
Ok(())
}
Error::Cancelled => writeln!(f, "Operation cancelled by delegate"),
Error::FieldClash(field) => writeln!(
f,
"The custom parameter '{}' is already provided natively by the CallBuilder.",
field
),
Error::MissingField(field) => writeln!(
f,
"The parameter '{}' is missing by the CallBuilder.",
field
),
Error::JsonError(ref json_str, ref err) => writeln!(f, "{}: {}", err, json_str),
Error::Failure(ref response) => {
writeln!(f, "Http status indicates failure: {:?}", response)
}
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match *self {
Error::HttpError(ref err) => err.source(),
Error::JsonError(_, ref err) => err.source(),
_ => None,
}
}
}
impl From<std::io::Error> for Error {
fn from(err: std::io::Error) -> Self {
Error::Io(err)
}
}
pub type Result<T> = std::result::Result<T, Error>;