Return 500 if email delivery fails.

This commit is contained in:
LukeMathWalker 2021-05-01 16:45:19 +01:00
parent 80aa2a4575
commit b778d9f6e2
2 changed files with 9 additions and 2 deletions

View file

@ -59,13 +59,14 @@ pub async fn subscribe(
.commit()
.await
.map_err(|_| HttpResponse::InternalServerError().finish())?;
let _ = send_confirmation_email(
send_confirmation_email(
&email_client,
new_subscriber,
&base_url.0,
&subscription_token,
)
.await;
.await
.map_err(|_| HttpResponse::InternalServerError().finish())?;
Ok(HttpResponse::Ok().finish())
}

View file

@ -8,6 +8,12 @@ async fn subscribe_returns_a_200_for_valid_form_data() {
let app = spawn_app().await;
let body = "name=le%20guin&email=ursula_le_guin%40gmail.com";
Mock::given(path("/email"))
.and(method("POST"))
.respond_with(ResponseTemplate::new(200))
.mount(&app.email_server)
.await;
// Act
let response = app.post_subscriptions(body.into()).await;