Fixed issue that loading state does not reset when database restarts #12
@ -92,6 +92,18 @@ struct SurrealResponse {
|
|||||||
result: SurrealResult,
|
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)]
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||||
struct SurrealAction {
|
struct SurrealAction {
|
||||||
id: String,
|
id: String,
|
||||||
@ -261,8 +273,8 @@ pub fn init_surrealdb() {
|
|||||||
fn surrealdb_response(response: String) {
|
fn surrealdb_response(response: String) {
|
||||||
let response: SurrealResponse = match serde_json::from_str(&response) {
|
let response: SurrealResponse = match serde_json::from_str(&response) {
|
||||||
Ok(res) => res,
|
Ok(res) => res,
|
||||||
Err(err) => {
|
Err(_) => {
|
||||||
log::warn!("{}", err);
|
handle_error(response);
|
||||||
return;
|
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
|
/// Function to execute when DB signin is succesful
|
||||||
fn use_surrealdb(response: SurrealResponse) {
|
fn use_surrealdb(response: SurrealResponse) {
|
||||||
util::toast::add_toast(
|
util::toast::add_toast(
|
||||||
|
Loading…
Reference in New Issue
Block a user