store: do not panic when kv reads null

instead, return an empty string.
This commit is contained in:
Peter Cai 2020-04-07 21:31:10 +08:00
parent 09081dd1d7
commit b910f25cc7
No known key found for this signature in database
GPG Key ID: 71F5FB4E4F3FD54F
1 changed files with 2 additions and 1 deletions

View File

@ -14,8 +14,9 @@ extern "C" {
fn kv_put_str(key: &str, value: &str) -> Promise;
}
// Returns empty string ("") if the key is not found
pub async fn get_str(key: &str) -> MyResult<String> {
Ok(JsFuture::from(kv_get(key)).await.internal_err()?.as_string().unwrap())
Ok(JsFuture::from(kv_get(key)).await.internal_err()?.as_string().unwrap_or("".into()))
}
pub async fn get_obj<T: DeserializeOwned>(key: &str) -> MyResult<T> {