Skip to content

Commit e0b8a9e

Browse files
committed
Replace console.log and console.error with Neutralino.debug.log in AuthStatus.tsx, AppInitializer.ts, auth.ts, and config-manager.ts.
Add error level logs to the user-facing console: * `AuthStatus.tsx`: Add detailed error messages for authentication, refresh, check, and logout processes. * `AppInitializer.ts`: Add error message for initialization. * `auth.ts`: Add error message for token saving and loading. * `config-manager.ts`: Add error message for config loading and saving. Expand fetch error messages to show full request and response details in `AuthStatus.tsx`.
1 parent 6c802ea commit e0b8a9e

File tree

4 files changed

+59
-12
lines changed

4 files changed

+59
-12
lines changed

client/src/components/AuthStatus.tsx

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@ export const AuthStatus: Component = () => {
2525
throw new Error(`Failed to open authentication window: ${error instanceof Error ? error.message : 'Unknown error'}`);
2626
}
2727
} catch (error) {
28-
Neutralino.debug.log('Error starting authentication: ' + (error instanceof Error ? error.message : 'Unknown error'), 'ERROR');
28+
const errorMessage = `Error starting authentication: ${error instanceof Error ? error.message : 'Unknown error'} | Request: ${JSON.stringify({ url: `${botServerUrl}/auth?redirect_uri=${window.location.origin}/auth.html&NL_TOKEN=${window.NL_TOKEN}` })}`;
29+
Neutralino.debug.log(errorMessage, 'ERROR');
30+
window.consoleAddMessage?.({
31+
text: errorMessage,
32+
type: 'error'
33+
});
2934
} finally {
3035
setIsLoading(false);
3136
}
@@ -60,9 +65,14 @@ export const AuthStatus: Component = () => {
6065
throw new Error('Failed to refresh authentication');
6166
}
6267
} catch (error) {
68+
const errorMessage = `Error refreshing authentication: ${error instanceof Error ? error.message : 'Unknown error'} | Request: ${JSON.stringify({ url: `${botServerUrl}/auth/refresh`, body: { refresh_token: authData.tokens.refresh_token } })} | Response: ${JSON.stringify(error.response)}`;
6369
await state.auth.saveAuthData(null);
6470
setIsAuthenticated(false);
65-
Neutralino.debug.log('Error refreshing authentication: ' + (error instanceof Error ? error.message : 'Unknown error'), 'ERROR');
71+
Neutralino.debug.log(errorMessage, 'ERROR');
72+
window.consoleAddMessage?.({
73+
text: errorMessage,
74+
type: 'error'
75+
});
6676
} finally {
6777
setIsLoading(false);
6878
}
@@ -86,7 +96,12 @@ export const AuthStatus: Component = () => {
8696
await authenticate();
8797
}
8898
} catch (error) {
89-
Neutralino.debug.log('Error checking authentication: ' + (error instanceof Error ? error.message : 'Unknown error'), 'ERROR');
99+
const errorMessage = `Error checking authentication: ${error instanceof Error ? error.message : 'Unknown error'} | Request: ${JSON.stringify({ url: `${botServerUrl}/auth/check` })}`;
100+
Neutralino.debug.log(errorMessage, 'ERROR');
101+
window.consoleAddMessage?.({
102+
text: errorMessage,
103+
type: 'error'
104+
});
90105
} finally {
91106
setIsLoading(false);
92107
}
@@ -101,7 +116,12 @@ export const AuthStatus: Component = () => {
101116
setIsAuthenticated(false);
102117
Neutralino.debug.log('Logged out successfully', 'INFO');
103118
} catch (error) {
104-
Neutralino.debug.log('Error during logout: ' + (error instanceof Error ? error.message : 'Unknown error'), 'ERROR');
119+
const errorMessage = `Error during logout: ${error instanceof Error ? error.message : 'Unknown error'}`;
120+
Neutralino.debug.log(errorMessage, 'ERROR');
121+
window.consoleAddMessage?.({
122+
text: errorMessage,
123+
type: 'error'
124+
});
105125
} finally {
106126
setIsLoading(false);
107127
}

client/src/services/AppInitializer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ class AppInitializer {
2727
Neutralino.debug.log('Application initialized successfully', 'INFO');
2828
} catch (error) {
2929
Neutralino.debug.log('Error during initialization: ' + (error instanceof Error ? error.message : 'Unknown error'), 'ERROR');
30+
window.consoleAddMessage?.({
31+
text: `Error during initialization: ${error instanceof Error ? error.message : 'Unknown error'}`,
32+
type: 'error'
33+
});
3034
throw error;
3135
}
3236
}

client/src/utils/auth.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ export class Auth {
3838
if (ev.detail.tokens) {
3939
await this.saveAuthData(ev.detail);
4040
} else {
41-
Neutralino.debug.log('No access token received in authentication callback', 'ERROR');
41+
const errorMessage = 'No access token received in authentication callback';
42+
Neutralino.debug.log(errorMessage, 'ERROR');
43+
window.consoleAddMessage?.({
44+
text: errorMessage,
45+
type: 'error'
46+
});
4247
}
4348
});
4449
}
@@ -54,7 +59,12 @@ export class Auth {
5459
Neutralino.debug.log('Auth data cleared successfully', 'INFO');
5560
}
5661
} catch (err) {
57-
Neutralino.debug.log('Error saving discord details to storage: ' + (err instanceof Error ? err.message : 'Unknown error'), 'ERROR');
62+
const errorMessage = `Error saving discord details to storage: ${err instanceof Error ? err.message : 'Unknown error'}`;
63+
Neutralino.debug.log(errorMessage, 'ERROR');
64+
window.consoleAddMessage?.({
65+
text: errorMessage,
66+
type: 'error'
67+
});
5868
throw err;
5969
}
6070
}
@@ -70,7 +80,12 @@ export class Auth {
7080
Neutralino.debug.log('No discord details found in storage', 'WARN');
7181
}
7282
} catch (err) {
73-
Neutralino.debug.log('Error getting discord details from storage: ' + (err instanceof Error ? err.message : 'Unknown error'), 'ERROR');
83+
const errorMessage = `Error getting discord details from storage: ${err instanceof Error ? err.message : 'Unknown error'}`;
84+
Neutralino.debug.log(errorMessage, 'ERROR');
85+
window.consoleAddMessage?.({
86+
text: errorMessage,
87+
type: 'error'
88+
});
7489
this.authData = null;
7590
}
7691
}

client/src/utils/config-manager.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,19 @@ export default class ConfigManager {
6464
const fileContent = await Neutralino.filesystem.readFile(this.configPath);
6565
const loadedConfig = JSON.parse(fileContent);
6666
this.config = this.deepMerge(this.defaultConfig, loadedConfig);
67-
Neutralino.debug.log('Config loaded successfully', 'INFO'); // P3998
67+
Neutralino.debug.log('Config loaded successfully', 'INFO');
6868
} else {
6969
this.config = { ...this.defaultConfig };
7070
await this.save();
7171
}
7272
this.isInitialized = true;
7373
} catch (error) {
74-
Neutralino.debug.log('Error loading config: ' + (error instanceof Error ? error.message : 'Unknown error'), 'ERROR'); // Peb86
75-
Neutralino.debug.log('Using default configuration...', 'WARN'); // Peb86
74+
Neutralino.debug.log('Error loading config: ' + (error instanceof Error ? error.message : 'Unknown error'), 'ERROR');
75+
window.consoleAddMessage?.({
76+
text: `Error loading config: ${error instanceof Error ? error.message : 'Unknown error'}`,
77+
type: 'error'
78+
});
79+
Neutralino.debug.log('Using default configuration...', 'WARN');
7680
this.config = { ...this.defaultConfig };
7781
await this.save();
7882
this.isInitialized = true;
@@ -105,9 +109,13 @@ export default class ConfigManager {
105109
async save(): Promise<void> {
106110
try {
107111
await Neutralino.filesystem.writeFile(this.configPath, JSON.stringify(this.config, null, 2));
108-
Neutralino.debug.log('Config saved successfully', 'INFO'); // P3998
112+
Neutralino.debug.log('Config saved successfully', 'INFO');
109113
} catch (error) {
110-
Neutralino.debug.log('Error saving config: ' + (error instanceof Error ? error.message : 'Unknown error'), 'ERROR'); // Peb86
114+
Neutralino.debug.log('Error saving config: ' + (error instanceof Error ? error.message : 'Unknown error'), 'ERROR');
115+
window.consoleAddMessage?.({
116+
text: `Error saving config: ${error instanceof Error ? error.message : 'Unknown error'}`,
117+
type: 'error'
118+
});
111119
throw error;
112120
}
113121
}

0 commit comments

Comments
 (0)