Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3735585
D14190.id46621.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D14190.id46621.diff
View Options
diff --git a/native/native_rust_library/src/backup.rs b/native/native_rust_library/src/backup.rs
--- a/native/native_rust_library/src/backup.rs
+++ b/native/native_rust_library/src/backup.rs
@@ -242,7 +242,11 @@
.map_err(|err| err.to_string());
let result = match latest_backup_id_response {
- Ok(result) => result,
+ Ok(Some(result)) => result,
+ Ok(None) => {
+ string_callback("".to_string(), promise_id, "null".to_string());
+ return;
+ }
Err(error) => {
string_callback(error, promise_id, "".to_string());
return;
@@ -321,14 +325,20 @@
async fn download_latest_backup_info(
user_identifier: String,
-) -> Result<LatestBackupInfoResponse, Box<dyn Error>> {
+) -> Result<Option<LatestBackupInfoResponse>, Box<dyn Error>> {
+ use backup_client::Error as BackupError;
let backup_client = BackupClient::new(BACKUP_SOCKET_ADDR)?;
let latest_backup_descriptor = BackupDescriptor::Latest { user_identifier };
- let backup_info_response = backup_client
+ let backup_info_response = match backup_client
.download_backup_data(&latest_backup_descriptor, RequestedData::BackupInfo)
- .await?;
+ .await
+ {
+ Ok(response) => response,
+ Err(BackupError::BackupNotFound) => return Ok(None),
+ Err(e) => return Err(e.into()),
+ };
let LatestBackupInfoResponse {
backup_id,
@@ -336,11 +346,11 @@
siwe_backup_msg,
} = serde_json::from_slice(&backup_info_response)?;
- Ok(LatestBackupInfoResponse {
+ Ok(Some(LatestBackupInfoResponse {
backup_id,
user_id,
siwe_backup_msg,
- })
+ }))
}
async fn download_backup_keys(
diff --git a/shared/backup_client/src/lib.rs b/shared/backup_client/src/lib.rs
--- a/shared/backup_client/src/lib.rs
+++ b/shared/backup_client/src/lib.rs
@@ -138,8 +138,15 @@
let response = request.send().await?;
- let result = response.error_for_status()?.bytes().await?.to_vec();
+ // this should be kept in sync with HTTP error conversions
+ // from `services/backup/src/error.rs`
+ match response.status() {
+ StatusCode::NOT_FOUND => return Err(Error::BackupNotFound),
+ StatusCode::BAD_REQUEST => return Err(Error::UserNotFound),
+ _ => (),
+ };
+ let result = response.error_for_status()?.bytes().await?.to_vec();
Ok(result)
}
}
@@ -397,7 +404,11 @@
WSClosed,
Unauthenticated,
InvalidRequest,
+ #[display(fmt = "user_not_found")]
+ UserNotFound,
+ BackupNotFound,
}
+
impl std::error::Error for Error {}
impl From<InvalidHeaderValue> for Error {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Jan 10, 4:53 AM (5 h, 56 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2844913
Default Alt Text
D14190.id46621.diff (2 KB)
Attached To
Mode
D14190: [native][backup_client] Handle BackupNotFound in retrieve_latest_backup_info
Attached
Detach File
Event Timeline
Log In to Comment