feat: return JSON responses for email registration errors and success messages
This commit is contained in:
parent
cf0d894092
commit
70f7f67d9c
@ -7,6 +7,7 @@ use lettre::message::header::ContentType;
|
||||
use lettre::transport::smtp::authentication::Credentials;
|
||||
use lettre::{Message, SmtpTransport, Transport};
|
||||
use serde::Deserialize;
|
||||
use serde_json::json;
|
||||
use std::fmt::Debug;
|
||||
use std::str::FromStr;
|
||||
use tracing::{error, info, instrument, warn};
|
||||
@ -26,7 +27,7 @@ pub async fn register(
|
||||
Err(e) => {
|
||||
let err = format!("Invalid email address: {e}");
|
||||
warn!(email = mail.email_address, error = %err);
|
||||
return (StatusCode::BAD_REQUEST, err);
|
||||
return (StatusCode::BAD_REQUEST, Json(json!({"error": err})));
|
||||
}
|
||||
};
|
||||
info!(email = mail.email_address, "RegistrationRequest received");
|
||||
@ -55,12 +56,18 @@ pub async fn register(
|
||||
match mailer.send(&verification_email) {
|
||||
Ok(_) => {
|
||||
info!(email = mail.email_address, "Verification email sent");
|
||||
(StatusCode::OK, "Verification email sent".to_string())
|
||||
(
|
||||
StatusCode::OK,
|
||||
Json(json!({"msg":"Verification email sent"})),
|
||||
)
|
||||
}
|
||||
Err(e) => {
|
||||
let err = format!("Failed to send verification email: {e}");
|
||||
error!(error = %err);
|
||||
(StatusCode::INTERNAL_SERVER_ERROR, err)
|
||||
(
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
Json(json!({"error": err})),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user