Skip to content

Instantly share code, notes, and snippets.

@lholden
Created January 10, 2017 23:38
Show Gist options
  • Save lholden/1954655c075543d98cc9e9a890a20079 to your computer and use it in GitHub Desktop.
Save lholden/1954655c075543d98cc9e9a890a20079 to your computer and use it in GitHub Desktop.
use uuid;
use postgres;
use r2d2;
use std::num;
#[derive(Debug, Serialize)]
pub enum Error {
InvalidParam(String),
DatabaseError(String),
RecordNotFound(String),
RecordNotSaved,
}
impl From<num::ParseIntError> for Error {
fn from(err: num::ParseIntError) -> Self {
Error::InvalidParam(format!("{}", err))
}
}
impl From<uuid::ParseError> for Error {
fn from(err: uuid::ParseError) -> Self {
Error::InvalidParam(format!("{}", err))
}
}
impl From<postgres::error::Error> for Error {
fn from(err: postgres::error::Error) -> Self {
Error::DatabaseError(format!("{}", err))
}
}
impl From<r2d2::GetTimeout> for Error {
fn from(err: r2d2::GetTimeout) -> Self {
Error::DatabaseError(format!("{}", err))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment