diff --git a/src/main.rs b/src/main.rs index 2133644..32bfe72 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,7 +36,7 @@ async fn root() -> &'static str { "KOreader sync server" } -async fn create_user(Json(payload): Json) -> StatusCode { +async fn create_user(Json(payload): Json) -> (StatusCode, String) { let client = redis::Client::open("redis://127.0.0.1/").unwrap(); let mut con = client.get_connection().unwrap(); @@ -50,10 +50,13 @@ async fn create_user(Json(payload): Json) -> StatusCode { if does_exist == false { let _: () = con.set(&user_key, password).unwrap(); } else { - return StatusCode::PAYMENT_REQUIRED; + return ( + StatusCode::PAYMENT_REQUIRED, + "Username is already registered.".to_owned(), + ); } - StatusCode::CREATED + (StatusCode::CREATED, format!("username = {username}")) } async fn auth_user(headers: HeaderMap) -> StatusCode {