Skip to content

Commit 77be9b4

Browse files
Anurag SinghAnurag Singh
Anurag Singh
authored and
Anurag Singh
committed
refactor: resolve PR comments
1 parent 628ae96 commit 77be9b4

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

crates/api_models/src/payments.rs

+11-22
Original file line numberDiff line numberDiff line change
@@ -7343,30 +7343,19 @@ impl AmazonPayDeliveryOptions {
73437343
.collect()
73447344
}
73457345

7346-
pub fn validate_is_default_count(delivery_options: Vec<Self>) -> Result<(), ValidationError> {
7347-
let is_default_count = i32::try_from(
7348-
delivery_options
7349-
.iter()
7350-
.filter(|delivery_option| delivery_option.is_default)
7351-
.count(),
7352-
)
7353-
.map_err(|_| ValidationError::InvalidValue {
7354-
message: "Invalid value provided: is_default".to_string(),
7355-
})?;
7356-
7357-
if is_default_count == 0 {
7358-
return Err(ValidationError::InvalidValue {
7359-
message: "Expected one default Amazon Pay Delivery Options, encountered none."
7360-
.to_string(),
7361-
});
7362-
}
7346+
pub fn validate_is_default_count(
7347+
delivery_options: Vec<Self>,
7348+
) -> Result<(), error_stack::Report<ValidationError>> {
7349+
let is_default_count = delivery_options
7350+
.iter()
7351+
.filter(|delivery_option| delivery_option.is_default)
7352+
.count();
73637353

7364-
if is_default_count > 1 {
7354+
if is_default_count != 1 {
73657355
return Err(ValidationError::InvalidValue {
7366-
message:
7367-
"Expected one default Amazon Pay Delivery Options, encountered more than one."
7368-
.to_string(),
7369-
});
7356+
message: "Amazon Pay Delivery Option".to_string(),
7357+
})
7358+
.attach_printable("Expected one default Amazon Pay Delivery Option");
73707359
}
73717360

73727361
Ok(())

0 commit comments

Comments
 (0)