aboutsummaryrefslogtreecommitdiffstats
path: root/atuin-server/src/handlers/user.rs
diff options
context:
space:
mode:
authorEllie Huxtable <ellie@elliehuxtable.com>2022-04-21 08:03:39 +0100
committerGitHub <noreply@github.com>2022-04-21 08:03:39 +0100
commited4e07d2e63af1584a262037781729a5144a5502 (patch)
tree38bdb691cd060860e7a3fced7901c74283ddf2f1 /atuin-server/src/handlers/user.rs
parentBump clap from 3.1.9 to 3.1.10 (#309) (diff)
downloadatuin-ed4e07d2e63af1584a262037781729a5144a5502.zip
Use the count cache (#312)
* Use the count cache By default read from the count cache - if there is no value there, then do a full COUNT. The cache will be filled when the user posts up some more history * clean up server db error handling Co-authored-by: Conrad Ludgate <conrad.ludgate@truelayer.com>
Diffstat (limited to 'atuin-server/src/handlers/user.rs')
-rw-r--r--atuin-server/src/handlers/user.rs25
1 files changed, 19 insertions, 6 deletions
diff --git a/atuin-server/src/handlers/user.rs b/atuin-server/src/handlers/user.rs
index 1bcfce2f..42e4aa33 100644
--- a/atuin-server/src/handlers/user.rs
+++ b/atuin-server/src/handlers/user.rs
@@ -32,10 +32,15 @@ pub async fn get(
) -> Result<Json<UserResponse>, ErrorResponseStatus<'static>> {
let user = match db.get_user(username.as_ref()).await {
Ok(user) => user,
- Err(e) => {
- debug!("user not found: {}", e);
+ Err(sqlx::Error::RowNotFound) => {
+ debug!("user not found: {}", username);
return Err(ErrorResponse::reply("user not found").with_status(StatusCode::NOT_FOUND));
}
+ Err(err) => {
+ error!("database error: {}", err);
+ return Err(ErrorResponse::reply("database error")
+ .with_status(StatusCode::INTERNAL_SERVER_ERROR));
+ }
};
Ok(Json(UserResponse {
@@ -96,20 +101,28 @@ pub async fn login(
) -> Result<Json<LoginResponse>, ErrorResponseStatus<'static>> {
let user = match db.get_user(login.username.borrow()).await {
Ok(u) => u,
+ Err(sqlx::Error::RowNotFound) => {
+ return Err(ErrorResponse::reply("user not found").with_status(StatusCode::NOT_FOUND));
+ }
Err(e) => {
error!("failed to get user {}: {}", login.username.clone(), e);
- return Err(ErrorResponse::reply("user not found").with_status(StatusCode::NOT_FOUND));
+ return Err(ErrorResponse::reply("database error")
+ .with_status(StatusCode::INTERNAL_SERVER_ERROR));
}
};
let session = match db.get_user_session(&user).await {
Ok(u) => u,
- Err(e) => {
- error!("failed to get session for {}: {}", login.username, e);
-
+ Err(sqlx::Error::RowNotFound) => {
+ debug!("user session not found for user id={}", user.id);
return Err(ErrorResponse::reply("user not found").with_status(StatusCode::NOT_FOUND));
}
+ Err(err) => {
+ error!("database error for user {}: {}", login.username, err);
+ return Err(ErrorResponse::reply("database error")
+ .with_status(StatusCode::INTERNAL_SERVER_ERROR));
+ }
};
let verified = verify_str(user.password.as_str(), login.password.borrow());