fix: improve error handling and display in desktop client enrollment flow
Add formatInvokeError helper function to handle various error types from Tauri invoke calls with fallback messages. Update enroll_device to include response body in error message when enrollment fails with non-success status. Add windows_subsystem attribute to main.rs to suppress console window in release builds on Windows.
This commit is contained in:
@@ -11,6 +11,18 @@ type EnrollmentState = {
|
||||
tunnelStrategy: string;
|
||||
};
|
||||
|
||||
function formatInvokeError(err: unknown, fallback: string) {
|
||||
if (typeof err === "string" && err.trim().length > 0) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (err instanceof Error && err.message.trim().length > 0) {
|
||||
return err.message;
|
||||
}
|
||||
|
||||
return fallback;
|
||||
}
|
||||
|
||||
export function App() {
|
||||
const [serverUrl, setServerUrl] = useState("http://localhost");
|
||||
const [username, setUsername] = useState("");
|
||||
@@ -41,7 +53,7 @@ export function App() {
|
||||
});
|
||||
setState(result);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : "Enrollment failed");
|
||||
setError(formatInvokeError(err, "Enrollment failed"));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -54,7 +66,7 @@ export function App() {
|
||||
setConnected((value) => !value);
|
||||
setError(null);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : "Tunnel action failed");
|
||||
setError(formatInvokeError(err, "Tunnel action failed"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user