fix previous auth records cleanup, update error enums

This commit is contained in:
yggverse 2024-11-20 10:03:46 +02:00
parent cadefe3f1d
commit 3191ff0ff0
2 changed files with 7 additions and 8 deletions

View File

@ -45,12 +45,10 @@ impl Auth {
// Get all records match request // Get all records match request
match self.database.records(Some(url)) { match self.database.records(Some(url)) {
Ok(records) => { Ok(records) => {
// Cleanup records match `profile_identity_gemini_id` (unauth) // Cleanup records match `url` (unauth)
for record in records { for record in records {
if record.profile_identity_gemini_id == profile_identity_gemini_id { if let Err(reason) = self.database.delete(record.id) {
if self.database.delete(record.id).is_err() { return Err(Error::DatabaseRecordDelete(record.id, reason));
return Err(Error::DatabaseRecordDelete(record.id));
}
} }
} }
@ -58,10 +56,11 @@ impl Auth {
let profile_identity_gemini_auth_id = let profile_identity_gemini_auth_id =
match self.database.add(profile_identity_gemini_id, url) { match self.database.add(profile_identity_gemini_id, url) {
Ok(id) => id, Ok(id) => id,
Err(_) => { Err(reason) => {
return Err(Error::DatabaseRecordCreate( return Err(Error::DatabaseRecordCreate(
profile_identity_gemini_id, profile_identity_gemini_id,
url.to_string(), url.to_string(),
reason,
)) ))
} }
}; };

View File

@ -1,8 +1,8 @@
#[derive(Debug)] #[derive(Debug)]
pub enum Error { pub enum Error {
DatabaseIndex, DatabaseIndex,
DatabaseRecordCreate(i64, String), DatabaseRecordCreate(i64, String, sqlite::Error),
DatabaseRecordDelete(i64), DatabaseRecordDelete(i64, sqlite::Error),
DatabaseRecordsRead(String), DatabaseRecordsRead(String),
MemoryIndex(super::memory::Error), MemoryIndex(super::memory::Error),
} }