Skip to content

Commit

Permalink
Fixed fn_name! macro usage
Browse files Browse the repository at this point in the history
  • Loading branch information
markcda committed Jun 11, 2024
1 parent 0e3e3b1 commit a591d30
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "cc-utils"
description = "Rust Fullstack utils (strict error handling, `Consider` trait, MessagePack support, etc.) for Salvo and Yew/Dioxus/Leptos/*"
version = "0.2.10"
version = "0.2.11"
edition = "2021"
license = "MIT"
authors = ["Klimenty Titov <aclo.create@gmail.com>"]
Expand Down
23 changes: 10 additions & 13 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ pub struct CliError {
impl ServerResponseWriter for ErrorResponse {
/// Method for sending an error message to the client.
async fn write(self, _req: &mut Request, _depot: &mut Depot, res: &mut Response) {
res.status_code(
self.status_code
.unwrap_or(StatusCode::INTERNAL_SERVER_ERROR),
);
res.status_code(self.status_code.unwrap_or(StatusCode::INTERNAL_SERVER_ERROR));
if !self.public_error {
let public_error_desc = match self.status_code {
Some(StatusCode::BAD_REQUEST) => "Bad request.",
Expand All @@ -57,21 +54,21 @@ impl ServerResponseWriter for ErrorResponse {
_ => "Specific error. Check with the administrator for details.",
};
log::error!(
"Error with code {:?}: \"{}\", client will get: \"{}\"",
self.status_code,
self.error_text,
public_error_desc
);
"Error with code {:?}: \"{}\", client will get: \"{}\"",
self.status_code,
self.error_text,
public_error_desc
);
if self.original_text.is_some() {
log::error!("The original error text: {:?}", self.original_text.unwrap());
}
res.render(public_error_desc);
} else {
log::error!(
"Error with code {:?}: \"{}\"",
self.status_code,
self.error_text
);
"Error with code {:?}: \"{}\"",
self.status_code,
self.error_text
);
if self.original_text.is_some() {
log::error!("The original error text: {:?}", self.original_text.unwrap());
}
Expand Down
6 changes: 3 additions & 3 deletions src/responses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl_oapi_endpoint_out!(Plain, "text/plain");

#[cfg(feature = "salvo")]
#[macro_export]
macro_rules! plain { ($e:expr) => { Ok(Plain($e, fn_name!())) }; }
macro_rules! plain { ($e:expr) => { Ok(Plain($e, cc_utils::fn_name!())) }; }

#[cfg(feature = "salvo")]
#[salvo::async_trait]
Expand All @@ -130,7 +130,7 @@ impl_oapi_endpoint_out!(Html, "text/html");

#[cfg(feature = "salvo")]
#[macro_export]
macro_rules! html { ($e:expr) => { Ok(Html($e, fn_name!())) }; }
macro_rules! html { ($e:expr) => { Ok(Html($e, cc_utils::fn_name!())) }; }

#[cfg(feature = "salvo")]
#[salvo::async_trait]
Expand Down Expand Up @@ -208,7 +208,7 @@ impl_oapi_endpoint_out_t!(MsgPack, "application/msgpack");

#[cfg(feature = "salvo")]
#[macro_export]
macro_rules! msgpack { ($e:expr) => { Ok(MsgPack($e, fn_name!())) }; }
macro_rules! msgpack { ($e:expr) => { Ok(MsgPack($e, cc_utils::fn_name!())) }; }

#[cfg(feature = "salvo")]
#[salvo::async_trait]
Expand Down

0 comments on commit a591d30

Please sign in to comment.