refactor: improve the error message

This commit is contained in:
Kevin Yue 2023-08-30 13:35:17 +08:00
parent 11a374765c
commit acf7ef28ab
2 changed files with 5 additions and 1 deletions

View File

@ -32,12 +32,15 @@ impl AppStorage<'_> {
} }
} }
/// Get a value from the store (.data.json).
/// If the value is encrypted, it will be decrypted.
/// If the value is not found, or if there is an error, `None` is returned.
pub fn get<T: DeserializeOwned + Debug>(&self, hint: KeyHint) -> Option<T> { pub fn get<T: DeserializeOwned + Debug>(&self, hint: KeyHint) -> Option<T> {
let stores = self.app_handle.state::<StoreCollection<Wry>>(); let stores = self.app_handle.state::<StoreCollection<Wry>>();
with_store(self.app_handle.clone(), stores, self.path, |store| { with_store(self.app_handle.clone(), stores, self.path, |store| {
store store
.get(hint.key) .get(hint.key)
.ok_or_else(|| Error::Deserialize("Value not found".into())) .ok_or_else(|| Error::Deserialize(format!("Key {} not found in store", hint.key).into()))
.and_then(|value| { .and_then(|value| {
if !hint.encrypted { if !hint.encrypted {
return Ok(serde_json::from_value::<T>(value.clone())?); return Ok(serde_json::from_value::<T>(value.clone())?);

View File

@ -66,6 +66,7 @@ export default function PasswordAuth() {
type="submit" type="submit"
loading={loading} loading={loading}
disabled={loading} disabled={loading}
sx={{ flex: 1 }}
> >
Login Login
</LoadingButton> </LoadingButton>