Some more error handling
This commit is contained in:
@ -6,8 +6,8 @@ use crate::error::*;
|
||||
|
||||
pub fn endpoint(endpoint: &str, input: serde_json::Value) -> Result<serde_json::Value, Error> {
|
||||
match endpoint {
|
||||
"echo" => Ok(serde_json::to_value(echo(serde_json::from_value(input)?))?),
|
||||
_ => Err(Error::new(ErrorKind::InvalidEndpointError)),
|
||||
"echo" => Ok(serde_json::to_value(echo(serde_json::from_value(input)?)?)?),
|
||||
_ => Err(Error::new(Kind::InvalidEndpointError, Class::ClientError)),
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,19 +22,19 @@ pub struct EchoOutput {
|
||||
database: Option<i32>,
|
||||
}
|
||||
|
||||
pub fn echo(input: EchoInput) -> EchoOutput {
|
||||
let backend = database::client();
|
||||
pub fn echo(input: EchoInput) -> Result<EchoOutput, Error> {
|
||||
let backend = database::client()?;
|
||||
let mut output = EchoOutput {
|
||||
message: input.message,
|
||||
database: None,
|
||||
};
|
||||
match backend {
|
||||
database::Client::Postgres(mut client) => {
|
||||
let res = client.query("SELECT * FROM test", &[]).unwrap();
|
||||
let res = client.query("SELECT * FROM test", &[])?;
|
||||
for row in res {
|
||||
output.database = Some(row.get(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
output
|
||||
Ok(output)
|
||||
}
|
||||
|
Reference in New Issue
Block a user