cargo fmt

Signed-off-by: ATechnoHazard <amolele@gmail.com>
This commit is contained in:
sphericalkat committed 2020-06-26 16:44:07 +05:30
1 parent 1aa0c5c278
commit 62df3f239a
24 files changed
+147 -114

No files matched your search

+2 -2
View File
@@ -1,6 +1,6 @@
use diesel::pg::PgConnection;
use diesel::{r2d2, Connection};
use diesel::r2d2::ConnectionManager;
use diesel::{r2d2, Connection};
use std::env;
pub type Pool = r2d2::Pool<ConnectionManager<PgConnection>>;
@@ -16,4 +16,4 @@ fn database_url() -> String {
pub fn pg_connection() -> PgConnection {
PgConnection::establish(database_url().as_str()).unwrap()
}
}
+23 -14
View File
@@ -1,8 +1,13 @@
use rocket::{http::{Status, ContentType}, response::Responder, Request, response, Response, Outcome, State};
use rocket::{
http::{ContentType, Status},
response,
response::Responder,
Outcome, Request, Response, State,
};
use std::io::Cursor;
use slog::Logger;
use slog;
use slog::Logger;
use std::io::Cursor;
#[derive(Debug, Serialize, Clone)]
pub enum ErrorCode {
@@ -32,14 +37,12 @@ impl Error {
Error {
code,
msg: "".to_string(),
}.set_msg()
}
.set_msg()
}
pub fn custom(code: ErrorCode, msg: String) -> Error {
Error {
code,
msg,
}
Error { code, msg }
}
fn get_status_code(&self) -> Status {
@@ -56,14 +59,16 @@ impl Error {
ErrorCode::NotAuthorized => Status::Forbidden,
ErrorCode::CorruptResource => Status::InternalServerError,
ErrorCode::LogicalConflict => Status::BadRequest,
ErrorCode::Unknown => Status::InternalServerError
ErrorCode::Unknown => Status::InternalServerError,
}
}
fn set_msg(mut self) -> Self {
self.msg = match self.code.clone() {
ErrorCode::InvalidCredentials => "invalid credentials were provided".to_string(),
ErrorCode::MultipleAuthToken => "multiple authorization tokens were provided".to_string(),
ErrorCode::MultipleAuthToken => {
"multiple authorization tokens were provided".to_string()
}
ErrorCode::NoAuthToken => "no authorization token was found".to_string(),
ErrorCode::AuthTokenCreationFailed => "authorization token creation failed".to_string(),
ErrorCode::MalformedAuthToken => "authorization token was malformed".to_string(),
@@ -71,10 +76,14 @@ impl Error {
ErrorCode::ResourceAlreadyExists => "the given resource already exists".to_string(),
ErrorCode::DatabaseError => "database error occured".to_string(),
ErrorCode::InvalidData => "invalid data provided".to_string(),
ErrorCode::NotAuthorized => "you are not authorized to perform the requested operation".to_string(),
ErrorCode::NotAuthorized => {
"you are not authorized to perform the requested operation".to_string()
}
ErrorCode::CorruptResource => "requested resource was corrupted".to_string(),
ErrorCode::LogicalConflict => "the request logically conflicts with the existing data".to_string(),
ErrorCode::Unknown => "unknown error occured".to_string()
ErrorCode::LogicalConflict => {
"the request logically conflicts with the existing data".to_string()
}
ErrorCode::Unknown => "unknown error occured".to_string(),
};
self
}
@@ -94,4 +103,4 @@ impl<'r> Responder<'r> for Error {
.sized_body(Cursor::new(serde_json::to_string(&self).unwrap()))
.ok()
}
}
}
+2 -2
View File
@@ -1,3 +1,3 @@
pub mod errors;
pub mod db;
pub mod phonetic_key;
pub mod errors;
pub mod phonetic_key;
+1 -1
View File
@@ -17,4 +17,4 @@ use uuid::Uuid;
pub fn get_random_id() -> String {
Uuid::new_v4().to_string()
}
}