Continuing with error refactoring.
This commit is contained in:
@@ -11,7 +11,6 @@ use super::{
|
||||
};
|
||||
use crate::{
|
||||
crypto::{generate_secret, hash_secret},
|
||||
domain::UserAppSecret,
|
||||
error::AppError,
|
||||
repository::{self, RepositoryError},
|
||||
};
|
||||
@@ -97,20 +96,9 @@ async fn upsert_user_app_secret(
|
||||
}
|
||||
|
||||
let now = chrono::Utc::now();
|
||||
if request.expires_at <= now {
|
||||
return Err(AppError::BadRequest(
|
||||
"expires_at must be in the future".to_owned(),
|
||||
));
|
||||
}
|
||||
|
||||
let generated_secret = generate_secret().map_err(|_| AppError::Internal)?;
|
||||
let secret = UserAppSecret {
|
||||
id: secret_id,
|
||||
app_id,
|
||||
secret_hash: hash_secret(&generated_secret),
|
||||
expires_at: request.expires_at,
|
||||
created_at: now,
|
||||
};
|
||||
let generated_secret = generate_secret().map_err(|_| AppError::Unknown)?;
|
||||
let hashed_secret = hash_secret(&generated_secret);
|
||||
let secret = request.into_domain(secret_id, app_id, hashed_secret, now)?;
|
||||
|
||||
let mut tx = pool.begin().await.map_err(RepositoryError::from)?;
|
||||
ensure_app_ownership(&mut tx, user_id, app_id).await?;
|
||||
|
||||
Reference in New Issue
Block a user