2020-12-05 15:57:11 +03:00
|
|
|
use reqwest::Error as reqwest_error;
|
2020-11-29 16:23:27 +03:00
|
|
|
use rusqlite::Error as sqlite_error;
|
|
|
|
use rusqlite::{named_params, params, Connection, Result};
|
2020-12-05 15:57:11 +03:00
|
|
|
use std::{fmt, io, io::Error as io_error};
|
2020-11-29 16:23:27 +03:00
|
|
|
use telegram_bot::Error as tg_error;
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub(crate) enum Error {
|
|
|
|
UserNotFound,
|
|
|
|
SQLITE3Error(sqlite_error),
|
|
|
|
TelegramError(tg_error),
|
2020-12-05 15:57:11 +03:00
|
|
|
ReqwestError(reqwest_error),
|
2020-11-29 16:23:27 +03:00
|
|
|
ConfNotFound,
|
2020-12-05 15:57:11 +03:00
|
|
|
IOError(io_error),
|
|
|
|
FileNotFound,
|
2020-11-29 16:23:27 +03:00
|
|
|
}
|
|
|
|
impl fmt::Display for Error {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
write!(f, "An error occurred.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<sqlite_error> for Error {
|
|
|
|
fn from(e: sqlite_error) -> Error {
|
|
|
|
return Error::SQLITE3Error(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<tg_error> for Error {
|
|
|
|
fn from(e: tg_error) -> Error {
|
|
|
|
return Error::TelegramError(e);
|
|
|
|
}
|
2020-12-05 15:57:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<reqwest_error> for Error {
|
|
|
|
fn from(e: reqwest_error) -> Error {
|
|
|
|
return Error::ReqwestError(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<io_error> for Error {
|
|
|
|
fn from(e: io_error) -> Error {
|
|
|
|
return Error::IOError(e);
|
|
|
|
}
|
|
|
|
}
|