add show/exec commands and refactor AppState
This commit is contained in:
@@ -116,12 +116,13 @@ pub enum SendResponseError {
|
||||
|
||||
// errors encountered while handling an HTTP request
|
||||
#[derive(Debug, ThisError, AsRefStr)]
|
||||
pub enum RequestError {
|
||||
pub enum HandlerError {
|
||||
#[error("Error writing to stream: {0}")]
|
||||
StreamIOError(#[from] std::io::Error),
|
||||
// #[error("Received invalid UTF-8 in request")]
|
||||
// InvalidUtf8,
|
||||
// MalformedHttpRequest,
|
||||
#[error("HTTP request malformed")]
|
||||
BadRequest(Vec<u8>),
|
||||
#[error("HTTP request too large")]
|
||||
RequestTooLarge,
|
||||
#[error("Error accessing credentials: {0}")]
|
||||
@@ -184,6 +185,41 @@ pub enum ClientInfoError {
|
||||
}
|
||||
|
||||
|
||||
// Errors encountered while requesting credentials via CLI (creddy show, creddy exec)
|
||||
#[derive(Debug, ThisError, AsRefStr)]
|
||||
pub enum RequestError {
|
||||
#[error("Credentials request failed: HTTP {0}")]
|
||||
Failed(String),
|
||||
#[error("Credentials request was rejected")]
|
||||
Rejected,
|
||||
#[error("Couldn't interpret the server's response")]
|
||||
MalformedHttpResponse,
|
||||
#[error("The server did not respond with valid JSON")]
|
||||
InvalidJson,
|
||||
#[error("Error reading/writing stream: {0}")]
|
||||
StreamIOError(#[from] std::io::Error),
|
||||
}
|
||||
|
||||
|
||||
// Errors encountered while running a subprocess (via creddy exec)
|
||||
#[derive(Debug, ThisError, AsRefStr)]
|
||||
pub enum ExecError {
|
||||
#[error("Please specify a command")]
|
||||
NoCommand,
|
||||
#[error("Failed to execute command: {0}")]
|
||||
ExecutionFailed(#[from] std::io::Error)
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, ThisError, AsRefStr)]
|
||||
pub enum CliError {
|
||||
#[error(transparent)]
|
||||
Request(#[from] RequestError),
|
||||
#[error(transparent)]
|
||||
Exec(#[from] ExecError),
|
||||
}
|
||||
|
||||
|
||||
// =========================
|
||||
// Serialize implementations
|
||||
// =========================
|
||||
@@ -209,15 +245,15 @@ impl_serialize_basic!(GetCredentialsError);
|
||||
impl_serialize_basic!(ClientInfoError);
|
||||
|
||||
|
||||
impl Serialize for RequestError {
|
||||
impl Serialize for HandlerError {
|
||||
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
|
||||
let mut map = serializer.serialize_map(None)?;
|
||||
map.serialize_entry("code", self.as_ref())?;
|
||||
map.serialize_entry("msg", &format!("{self}"))?;
|
||||
|
||||
match self {
|
||||
RequestError::NoCredentials(src) => map.serialize_entry("source", &src)?,
|
||||
RequestError::ClientInfo(src) => map.serialize_entry("source", &src)?,
|
||||
HandlerError::NoCredentials(src) => map.serialize_entry("source", &src)?,
|
||||
HandlerError::ClientInfo(src) => map.serialize_entry("source", &src)?,
|
||||
_ => serialize_upstream_err(self, &mut map)?,
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user