Fixed issue that loading state does not reset when database restarts
This commit is contained in:
parent
6aadc89530
commit
bcf843765a
@ -92,6 +92,18 @@ struct SurrealResponse {
|
||||
result: SurrealResult,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
struct SurrealResultError {
|
||||
code: i32,
|
||||
message: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone)]
|
||||
struct SurrealResponseError {
|
||||
id: u32,
|
||||
error: SurrealResultError,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
struct SurrealAction {
|
||||
id: String,
|
||||
@ -261,8 +273,8 @@ pub fn init_surrealdb() {
|
||||
fn surrealdb_response(response: String) {
|
||||
let response: SurrealResponse = match serde_json::from_str(&response) {
|
||||
Ok(res) => res,
|
||||
Err(err) => {
|
||||
log::warn!("{}", err);
|
||||
Err(_) => {
|
||||
handle_error(response);
|
||||
return;
|
||||
}
|
||||
};
|
||||
@ -282,6 +294,26 @@ fn surrealdb_response(response: String) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Function to execute when an error is returned from Surrealdb
|
||||
fn handle_error(response: String) {
|
||||
let response: SurrealResponseError = match serde_json::from_str(&response) {
|
||||
Ok(res) => res,
|
||||
Err(err) => {
|
||||
log::warn!("{}", err);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
if response.id == 0 && response.error.code == -32000 {
|
||||
let (_, _, remove_token) =
|
||||
use_local_storage::<String, FromToStringCodec>("surrealdb-token");
|
||||
let websocket = expect_context::<SurrealContext>();
|
||||
|
||||
remove_token();
|
||||
websocket.set_loading.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
/// Function to execute when DB signin is succesful
|
||||
fn use_surrealdb(response: SurrealResponse) {
|
||||
util::toast::add_toast(
|
||||
|
Loading…
Reference in New Issue
Block a user