Skip to content

Commit f14f87a

Browse files
authored
deps(api_models): put the errors module behind a feature flag (#815)
1 parent 324df4d commit f14f87a

File tree

8 files changed

+23
-18
lines changed

8 files changed

+23
-18
lines changed

crates/api_models/Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@ version = "0.1.0"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
[features]
8+
errors = [
9+
"dep:actix-web",
10+
"dep:reqwest",
11+
]
712

813
[dependencies]
9-
actix-web = "4.3.1"
14+
actix-web = { version = "4.3.1", optional = true }
1015
error-stack = "0.3.1"
1116
frunk = "0.4.1"
1217
frunk_core = "0.4.1"
1318
mime = "0.3.16"
14-
reqwest = "0.11.14"
19+
reqwest = { version = "0.11.14", optional = true }
1520
serde = { version = "1.0.155", features = ["derive"] }
1621
serde_json = "1.0.94"
1722
strum = { version = "0.24.1", features = ["derive"] }

crates/api_models/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub mod cards_info;
66
pub mod customers;
77
pub mod disputes;
88
pub mod enums;
9+
#[cfg(feature = "errors")]
910
pub mod errors;
1011
pub mod files;
1112
pub mod mandates;

crates/api_models/src/webhooks.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,6 @@ impl From<IncomingWebhookEvent> for WebhookFlow {
5050
}
5151
}
5252

53-
pub struct IncomingWebhookRequestDetails<'a> {
54-
pub method: actix_web::http::Method,
55-
pub headers: &'a actix_web::http::header::HeaderMap,
56-
pub body: &'a [u8],
57-
pub query_params: String,
58-
pub query_params_json: &'a [u8],
59-
}
60-
6153
pub type MerchantWebhookConfig = std::collections::HashSet<IncomingWebhookEvent>;
6254

6355
pub enum RefundIdType {

crates/router/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ utoipa-swagger-ui = { version = "3.1.0", features = ["actix-web"] }
7979
uuid = { version = "1.3.0", features = ["serde", "v4"] }
8080

8181
# First party crates
82-
api_models = { version = "0.1.0", path = "../api_models" }
82+
api_models = { version = "0.1.0", path = "../api_models", features = ["errors"] }
8383
common_utils = { version = "0.1.0", path = "../common_utils" }
8484
external_services = { version = "0.1.0", path = "../external_services" }
8585
masking = { version = "0.1.0", path = "../masking" }

crates/router/src/connector/adyen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ impl api::IncomingWebhook for Adyen {
783783

784784
fn get_dispute_details(
785785
&self,
786-
request: &api_models::webhooks::IncomingWebhookRequestDetails<'_>,
786+
request: &api::IncomingWebhookRequestDetails<'_>,
787787
) -> CustomResult<api::disputes::DisputePayload, errors::ConnectorError> {
788788
let notif = get_webhook_object_from_body(request.body)
789789
.change_context(errors::ConnectorError::WebhookBodyDecodingFailed)?;

crates/router/src/connector/trustpay.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ impl api::IncomingWebhook for Trustpay {
722722

723723
fn get_dispute_details(
724724
&self,
725-
request: &api_models::webhooks::IncomingWebhookRequestDetails<'_>,
725+
request: &api::IncomingWebhookRequestDetails<'_>,
726726
) -> CustomResult<api::disputes::DisputePayload, errors::ConnectorError> {
727727
let trustpay_response: trustpay::TrustpayWebhookResponse = request
728728
.body

crates/router/src/core/webhooks.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ async fn disputes_incoming_webhook_flow<W: api::OutgoingWebhookType>(
301301
webhook_details: api::IncomingWebhookDetails,
302302
source_verified: bool,
303303
connector: &(dyn api::Connector + Sync),
304-
request_details: &api_models::webhooks::IncomingWebhookRequestDetails<'_>,
304+
request_details: &api::IncomingWebhookRequestDetails<'_>,
305305
event_type: api_models::webhooks::IncomingWebhookEvent,
306306
) -> CustomResult<(), errors::WebhooksFlowError> {
307307
metrics::INCOMING_DISPUTE_WEBHOOK_METRIC.add(&metrics::CONTEXT, 1, &[]);
@@ -497,7 +497,7 @@ pub async fn webhooks_core<W: api::OutgoingWebhookType>(
497497
.change_context(errors::ApiErrorResponse::InternalServerError)
498498
.attach_printable("There was an error in parsing the query params")?;
499499

500-
let mut request_details = api_models::webhooks::IncomingWebhookRequestDetails {
500+
let mut request_details = api::IncomingWebhookRequestDetails {
501501
method: req.method().clone(),
502502
headers: req.headers(),
503503
query_params: req.query_string().to_string(),

crates/router/src/types/api/webhooks.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
pub use api_models::webhooks::{
2-
IncomingWebhookDetails, IncomingWebhookEvent, IncomingWebhookRequestDetails,
3-
MerchantWebhookConfig, ObjectReferenceId, OutgoingWebhook, OutgoingWebhookContent,
4-
OutgoingWebhookType, WebhookFlow,
2+
IncomingWebhookDetails, IncomingWebhookEvent, MerchantWebhookConfig, ObjectReferenceId,
3+
OutgoingWebhook, OutgoingWebhookContent, OutgoingWebhookType, WebhookFlow,
54
};
65
use error_stack::ResultExt;
76

@@ -13,6 +12,14 @@ use crate::{
1312
utils::crypto,
1413
};
1514

15+
pub struct IncomingWebhookRequestDetails<'a> {
16+
pub method: actix_web::http::Method,
17+
pub headers: &'a actix_web::http::header::HeaderMap,
18+
pub body: &'a [u8],
19+
pub query_params: String,
20+
pub query_params_json: &'a [u8],
21+
}
22+
1623
#[async_trait::async_trait]
1724
pub trait IncomingWebhook: ConnectorCommon + Sync {
1825
fn get_webhook_body_decoding_algorithm(

0 commit comments

Comments
 (0)