refactor: rename `errors` module to `messages` to match its purpose
Diff
src/data.rs | 2 +-
src/errors.rs | 40 ----------------------------------------
src/main.rs | 4 ++--
src/messages.rs | 40 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 43 insertions(+), 43 deletions(-)
@@ -2,7 +2,7 @@ use serde::Deserialize;
use std::str::FromStr;
use tide::log;
use crate::errors::{ErrorMsg, SuccessMsg};
use crate::messages::{ErrorMsg, SuccessMsg};
#[derive(Debug, Deserialize, Clone)]
pub struct LicenseDatabase {
@@ -1,40 +0,0 @@
use std::fmt::Display;
#[derive(Debug)]
pub enum ErrorMsg {
DatabaseError,
NoLicensesAvailable,
InvalidLicenseRequest,
InvalidLicense,
LicenseReadError,
}
impl Display for ErrorMsg {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let message = match self {
ErrorMsg::LicenseReadError => "Unable to read license file:",
ErrorMsg::DatabaseError => "Unable to load or parse license database.",
ErrorMsg::NoLicensesAvailable => "No licenses found.",
ErrorMsg::InvalidLicenseRequest => {
"Invalid license. use the 'list' or 'list/all' endpoints to see defined licenses."
}
ErrorMsg::InvalidLicense => "Invalid license requested:",
};
write!(f, "{}", message)
}
}
#[derive(Debug)]
pub enum SuccessMsg {
DatabaseLoaded,
}
impl Display for SuccessMsg {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let message = match self {
SuccessMsg::DatabaseLoaded => "Database loaded successfully!",
};
write!(f, "{}", message)
}
}
@@ -8,12 +8,12 @@ use tide::{http::mime, log, Response, Result, Server, StatusCode};
use crate::{
config::{RunningConfig, ServerConfig},
data::Queryable,
errors::ErrorMsg,
messages::ErrorMsg,
};
mod config;
mod data;
mod errors;
mod messages;
#[async_std::main]
async fn main() -> Result<()> {
@@ -0,0 +1,40 @@
use std::fmt::Display;
#[derive(Debug)]
pub enum ErrorMsg {
DatabaseError,
NoLicensesAvailable,
InvalidLicenseRequest,
InvalidLicense,
LicenseReadError,
}
impl Display for ErrorMsg {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let message = match self {
ErrorMsg::LicenseReadError => "Unable to read license file:",
ErrorMsg::DatabaseError => "Unable to load or parse license database.",
ErrorMsg::NoLicensesAvailable => "No licenses found.",
ErrorMsg::InvalidLicenseRequest => {
"Invalid license. use the 'list' or 'list/all' endpoints to see defined licenses."
}
ErrorMsg::InvalidLicense => "Invalid license requested:",
};
write!(f, "{}", message)
}
}
#[derive(Debug)]
pub enum SuccessMsg {
DatabaseLoaded,
}
impl Display for SuccessMsg {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let message = match self {
SuccessMsg::DatabaseLoaded => "Database loaded successfully!",
};
write!(f, "{}", message)
}
}