Skip to content

Commit

Permalink
Avoid direct http crate dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
jayvdb committed Mar 8, 2024
1 parent 3c31f15 commit d728086
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"
members = [
"actix-web-thiserror",
"actix-web-thiserror-derive",
Expand Down
2 changes: 1 addition & 1 deletion actix-web-thiserror-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ name = "actix_web_thiserror_derive"
proc-macro = true

[dependencies]
actix-web = "4.3.1"
arc-swap = "1.6.0"
http = "0.2.9"
lazy_static = "1.4.0"
proc-macro2 = "1.0.56"
quote = "1.0.26"
Expand Down
8 changes: 4 additions & 4 deletions actix-web-thiserror-derive/src/response_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ pub fn derive_response_error(input: TokenStream) -> TokenStream {

let expanded = quote! {
impl ::actix_web_thiserror::ThiserrorResponse for #name {
fn status_code(&self) -> Option<http::StatusCode> {
fn status_code(&self) -> Option<actix_web::http::StatusCode> {
match self {
#status_code_match
_ => None,
Expand All @@ -220,7 +220,7 @@ pub fn derive_response_error(input: TokenStream) -> TokenStream {
}

impl actix_web::error::ResponseError for #name {
fn status_code(&self) -> http::StatusCode {
fn status_code(&self) -> actix_web::http::StatusCode {
match ::actix_web_thiserror::ThiserrorResponse::status_code(self) {
Some(status_code) => status_code,
_ => {
Expand Down Expand Up @@ -311,7 +311,7 @@ fn get_status_code_literal(tokens: &mut Peekable<IntoIter>) -> Option<proc_macro
.to_string()
.parse::<u16>()
.ok()
.and_then(|status| http::StatusCode::from_u16(status).ok())
.and_then(|status| actix_web::http::StatusCode::from_u16(status).ok())
.is_none()
{
panic!("invalid status code");
Expand Down Expand Up @@ -345,7 +345,7 @@ fn get_status_code(tokens: &mut Peekable<IntoIter>) -> Option<proc_macro2::Token

Some(TokenTree::Literal(_)) => get_status_code_literal(tokens).map(|tokens| {
quote! {
http::StatusCode::from_u16(#tokens as u16)
actix_web::http::StatusCode::from_u16(#tokens as u16)
.unwrap_or_else(|_| unreachable!())
}
}),
Expand Down
1 change: 0 additions & 1 deletion actix-web-thiserror/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ documentation = "https://docs.rs/actix-web-thiserror"
actix-web = "4.3.1"
actix-web-thiserror-derive = { version = "0.2.0", path = "../actix-web-thiserror-derive" }
arc-swap = "1.6.0"
http = "0.2.9"
lazy_static = "1.4.0"
serde_json = "1.0.96"

Expand Down
12 changes: 6 additions & 6 deletions actix-web-thiserror/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ pub trait ResponseTransform {
&self,
name: &str,
err: &dyn std::error::Error,
status_code: http::StatusCode,
status_code: actix_web::http::StatusCode,
reason: Option<serde_json::Value>,
) -> HttpResponse {
actix_web::HttpResponse::build(status_code).finish()
}

fn default_error_status_code(&self) -> http::StatusCode {
http::StatusCode::INTERNAL_SERVER_ERROR
fn default_error_status_code(&self) -> actix_web::http::StatusCode {
actix_web::http::StatusCode::INTERNAL_SERVER_ERROR
}
}

Expand All @@ -121,7 +121,7 @@ pub fn set_global_transform(transform: impl ResponseTransform + Sync + Send + 's
pub fn apply_global_transform(
name: &str,
err: &dyn std::error::Error,
status_code: http::StatusCode,
status_code: actix_web::http::StatusCode,
reason: Option<serde_json::Value>,
) -> HttpResponse {
ResponseTransform::transform(
Expand All @@ -134,13 +134,13 @@ pub fn apply_global_transform(
}

#[doc(hidden)]
pub fn default_global_error_status_code() -> http::StatusCode {
pub fn default_global_error_status_code() -> actix_web::http::StatusCode {
ResponseTransform::default_error_status_code((&**RESPONSE_TRANSFORM.load()).as_ref())
}

#[doc(hidden)]
pub trait ThiserrorResponse {
fn status_code(&self) -> Option<http::StatusCode> {
fn status_code(&self) -> Option<actix_web::http::StatusCode> {
None
}

Expand Down

0 comments on commit d728086

Please sign in to comment.