Skip to content

Commit 73c663c

Browse files
committed
🟢 Return bad request when subscriptions is 0
1 parent 540829b commit 73c663c

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

exercises/tiered_pricing/solutions/isaac1024_baby-steps/src/tiered_pricing.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,20 @@ struct Subscriptions {
1212
pricing: u32,
1313
}
1414

15+
#[derive(Serialize, Deserialize)]
16+
struct BadRequestMessage {
17+
error_message: String,
18+
}
19+
1520
pub async fn tiered_pricing(pricing: web::Query<Pricing>) -> impl Responder {
16-
let total_price = get_total_subscription_price(pricing.subscriptions).unwrap();
17-
HttpResponse::Ok().json(Subscriptions {
18-
pricing: total_price,
19-
})
21+
match get_total_subscription_price(pricing.subscriptions) {
22+
Ok(total_price) => HttpResponse::Ok().json(Subscriptions {
23+
pricing: total_price,
24+
}),
25+
Err(error) => HttpResponse::BadRequest().json(BadRequestMessage {
26+
error_message: error.to_string(),
27+
}),
28+
}
2029
}
2130

2231
type SubscriptionResult<T> = Result<T, NumberSubscriptionsError>;

0 commit comments

Comments
 (0)