-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
154 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,42 @@ | ||
# | ||
# For all clippy lints please visit: https://rust-lang.github.io/rust-clippy/master/ | ||
# | ||
deny = [ | ||
# Prevent spelling mistakes in lints | ||
'unknown_lints', | ||
# clippy groups: | ||
'clippy::correctness', | ||
# All clippy allows must have a reason | ||
# TODO: enable lint-reasons feature | ||
# 'clippy::allow_attributes_without_reason', | ||
# Docs | ||
#'missing_docs', | ||
# 'clippy::missing_errors_doc', | ||
# 'clippy::missing_safety_doc', | ||
# 'clippy::missing_panics_doc', | ||
|
||
# Common mistakes | ||
'clippy::await_holding_lock', | ||
'unused_variables', | ||
'unused_imports', | ||
'dead_code', | ||
'unused_extern_crates', | ||
'unused_must_use', | ||
'unreachable_patterns', | ||
'clippy::cast_lossless', | ||
'clippy::cloned_instead_of_copied', | ||
'clippy::correctness', | ||
'clippy::create_dir', | ||
'clippy::dbg_macro', | ||
'clippy::else_if_without_else', | ||
'clippy::explicit_into_iter_loop', | ||
'clippy::explicit_iter_loop', | ||
'clippy::if_not_else', | ||
'clippy::inline_always', | ||
'clippy::let_underscore_drop', | ||
'clippy::let_unit_value', | ||
'clippy::match_bool', | ||
'clippy::match_on_vec_items', | ||
'clippy::match_wild_err_arm', | ||
# In crypto code, it is fairly common to have similar names e.g. `owner_pk` and `owner_k` | ||
# 'clippy::similar_names', | ||
'clippy::needless_borrow', | ||
# style | ||
'clippy::style', | ||
'clippy::explicit_into_iter_loop', | ||
'clippy::explicit_iter_loop', | ||
'clippy::if_not_else', | ||
'clippy::match_bool', | ||
# Although generally good practice, this is disabled because the code becomes worse | ||
# or needs mod-level exclusion in these cases: | ||
# tauri commands, blockchain async db needs owned copy, &Arc<T>, Copy types, T: AsRef<..>, T: ToString | ||
# 'clippy::needless_pass_by_value', | ||
'clippy::needless_question_mark', | ||
'clippy::nonminimal_bool', | ||
'clippy::range_plus_one', | ||
'clippy::struct_excessive_bools', | ||
'clippy::style', | ||
'clippy::too_many_lines', | ||
'clippy::trivially_copy_pass_by_ref', | ||
# Highlights potential casting mistakes | ||
'clippy::cast_lossless', | ||
# 'clippy::cast_possible_truncation', | ||
# 'clippy::cast_possible_wrap', | ||
# Precision loss is almost always competely fine and is only useful as a sanity check. | ||
# https://rust-lang.github.io/rust-clippy/master/index.html#cast_precision_loss | ||
# 'clippy::cast_precision_loss', | ||
# 'clippy::cast_sign_loss' | ||
'clippy::unnecessary_to_owned', | ||
'clippy::nonminimal_bool', | ||
'clippy::needless_question_mark', | ||
'dead_code', | ||
'unknown_lints', | ||
'unreachable_patterns', | ||
'unused_extern_crates', | ||
'unused_imports', | ||
'unused_must_use', | ||
'unused_variables', | ||
] | ||
|
||
allow = [ | ||
# allow Default::default calls | ||
'clippy::default_trait_access', | ||
# Generally when developers fix this, it can lead to leaky abstractions or worse, so | ||
# too many arguments is generally the lesser of two evils | ||
'clippy::too_many_arguments' | ||
'clippy::too_many_arguments', | ||
] | ||
warn = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use std::fmt::{Display, Formatter}; | ||
|
||
use actix_web::{ | ||
error::ResponseError, | ||
http::{header::ContentType, StatusCode}, | ||
HttpResponse, | ||
}; | ||
use thiserror::Error; | ||
|
||
#[derive(Debug, Clone, Error)] | ||
pub enum ServerError { | ||
/// Invalid signature | ||
InvalidSignature, | ||
/// Payload deserialization error | ||
CouldNotDeserializePayload, | ||
/// Could not read request body: {0} | ||
InvalidRequestBody(String), | ||
/// Invalid or missing github event header: {0} | ||
InvalidEventHeader(String), | ||
} | ||
|
||
impl ResponseError for ServerError { | ||
fn error_response(&self) -> HttpResponse { | ||
HttpResponse::build(self.status_code()) | ||
.insert_header(ContentType::html()) | ||
.body(self.to_string()) | ||
} | ||
|
||
fn status_code(&self) -> StatusCode { | ||
match *self { | ||
Self::InvalidSignature => StatusCode::UNAUTHORIZED, | ||
Self::CouldNotDeserializePayload => StatusCode::INTERNAL_SERVER_ERROR, | ||
Self::InvalidRequestBody(_) => StatusCode::BAD_REQUEST, | ||
Self::InvalidEventHeader(_) => StatusCode::BAD_REQUEST, | ||
} | ||
} | ||
} | ||
|
||
impl Display for ServerError { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
f.write_str(self.to_string().as_str()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod config; | ||
pub mod error; | ||
pub mod routes; | ||
pub mod server; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters