feat: enhance login status management and improve error logging across services

This commit is contained in:
zimplexing
2025-07-15 21:41:38 +08:00
parent 116cf12ca3
commit d44e9fe9ae
17 changed files with 62 additions and 57 deletions

View File

@@ -1,4 +1,3 @@
import useAuthStore from "@/stores/authStore";
// region: --- Interface Definitions ---
export interface DoubanItem {
@@ -97,7 +96,6 @@ export class API {
const response = await fetch(`${this.baseURL}${url}`, options);
if (response.status === 401) {
useAuthStore.getState().showLoginModal();
throw new Error("UNAUTHORIZED");
}

View File

@@ -47,7 +47,7 @@ export const fetchAndParseM3u = async (m3uUrl: string): Promise<Channel[]> => {
const m3uText = await response.text();
return parseM3U(m3uText);
} catch (error) {
console.error("Error fetching or parsing M3U:", error);
console.info("Error fetching or parsing M3U:", error);
return []; // Return empty array on error
}
};

View File

@@ -25,7 +25,7 @@ const getRemotePageHTML = () => {
</div>
<script>
window.addEventListener('DOMContentLoaded', () => {
fetch('/handshake', { method: 'POST' }).catch(console.error);
fetch('/handshake', { method: 'POST' }).catch(console.info);
});
function send() {
const input = document.getElementById("text");
@@ -36,7 +36,7 @@ const getRemotePageHTML = () => {
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message: value })
})
.catch(err => console.error(err));
.catch(err => console.info(err));
input.value = '';
}
}
@@ -80,7 +80,7 @@ class RemoteControlService {
body: JSON.stringify({ status: "ok" }),
};
} catch (parseError) {
console.error("[RemoteControl] Failed to parse message body:", parseError);
console.info("[RemoteControl] Failed to parse message body:", parseError);
return {
statusCode: 400,
headers: { "Content-Type": "application/json" },
@@ -102,7 +102,7 @@ class RemoteControlService {
};
}
} catch (error) {
console.error("[RemoteControl] Request handler error:", error);
console.info("[RemoteControl] Request handler error:", error);
return {
statusCode: 500,
headers: { "Content-Type": "application/json" },
@@ -125,7 +125,7 @@ class RemoteControlService {
console.log(`[RemoteControl] Server started successfully at: ${url}`);
return url;
} catch (error) {
console.error("[RemoteControl] Failed to start server:", error);
console.info("[RemoteControl] Failed to start server:", error);
throw new Error(error instanceof Error ? error.message : "Failed to start server");
}
}

View File

@@ -42,7 +42,7 @@ export class PlayerSettingsManager {
const data = await AsyncStorage.getItem(STORAGE_KEYS.PLAYER_SETTINGS);
return data ? JSON.parse(data) : {};
} catch (error) {
console.error("Failed to get all player settings:", error);
console.info("Failed to get all player settings:", error);
return {};
}
}
@@ -192,13 +192,13 @@ export class SettingsManager {
sources: {},
},
m3uUrl:
"https://ghfast.top/https://raw.githubusercontent.com/sjnhnp/adblock/refs/heads/main/filtered_http_only_valid.m3u",
"",
};
try {
const data = await AsyncStorage.getItem(STORAGE_KEYS.SETTINGS);
return data ? { ...defaultSettings, ...JSON.parse(data) } : defaultSettings;
} catch (error) {
console.error("Failed to get settings:", error);
console.info("Failed to get settings:", error);
return defaultSettings;
}
}

View File

@@ -59,7 +59,7 @@ class TCPHttpServer {
return { method, url, headers, body };
} catch (error) {
console.error('[TCPHttpServer] Error parsing HTTP request:', error);
console.info('[TCPHttpServer] Error parsing HTTP request:', error);
return null;
}
}
@@ -140,7 +140,7 @@ class TCPHttpServer {
socket.write(errorResponse);
}
} catch (error) {
console.error('[TCPHttpServer] Error handling request:', error);
console.info('[TCPHttpServer] Error handling request:', error);
const errorResponse = this.formatHttpResponse({
statusCode: 500,
headers: { 'Content-Type': 'text/plain' },
@@ -155,7 +155,7 @@ class TCPHttpServer {
});
socket.on('error', (error: Error) => {
console.error('[TCPHttpServer] Socket error:', error);
console.info('[TCPHttpServer] Socket error:', error);
});
socket.on('close', () => {
@@ -170,13 +170,13 @@ class TCPHttpServer {
});
this.server.on('error', (error: Error) => {
console.error('[TCPHttpServer] Server error:', error);
console.info('[TCPHttpServer] Server error:', error);
this.isRunning = false;
reject(error);
});
} catch (error) {
console.error('[TCPHttpServer] Failed to start server:', error);
console.info('[TCPHttpServer] Failed to start server:', error);
reject(error);
}
});