File tree Expand file tree Collapse file tree 4 files changed +32
-11
lines changed Expand file tree Collapse file tree 4 files changed +32
-11
lines changed Original file line number Diff line number Diff line change @@ -12,8 +12,8 @@ export default {
1212 placeholder : 'Select database type' ,
1313 description : 'Choose SQLite for quick setup or PostgreSQL for production use.' ,
1414 options : {
15- sqlite : 'SQLite (Recommended for development) ' ,
16- postgres : 'PostgreSQL (Production ready) ' ,
15+ sqlite : 'SQLite' ,
16+ postgres : 'PostgreSQL' ,
1717 } ,
1818 } ,
1919 connectionString : {
@@ -29,6 +29,7 @@ export default {
2929 errors : {
3030 title : 'Setup Failed' ,
3131 connectionFailed : 'Failed to connect to backend. Please ensure the server is running.' ,
32+ failedToConnectWithAddress : 'Failed to connect to backend. Please ensure the server is running (remote address {address}).' ,
3233 setupFailed : 'Failed to setup database. Please try again.' ,
3334 validationRequired : 'Please select a database type' ,
3435 connectionStringRequired : 'Connection string is required for PostgreSQL' ,
Original file line number Diff line number Diff line change @@ -29,7 +29,12 @@ class DatabaseService {
2929 return data ;
3030 } catch ( error ) {
3131 console . error ( 'Failed to check database status:' , error ) ;
32- throw new Error ( 'setup.errors.connectionFailed' ) ;
32+ // Throw an error object that the store can inspect
33+ throw {
34+ isCustomError : true ,
35+ i18nKey : 'setup.errors.failedToConnectWithAddress' ,
36+ address : this . baseUrl
37+ } ;
3338 }
3439 }
3540
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ export const useDatabaseStore = defineStore('database', () => {
1010 const dialect = ref < DatabaseType | null > ( null ) ;
1111 const isLoading = ref ( false ) ;
1212 const error = ref < string | null > ( null ) ;
13+ const errorAddress = ref < string | null > ( null ) ; // Added
1314 const setupCompleted = ref ( false ) ;
1415
1516 // Computed
@@ -41,8 +42,16 @@ export const useDatabaseStore = defineStore('database', () => {
4142 setupCompleted . value = status . configured && status . initialized ;
4243
4344 return canProceedToApp . value ;
44- } catch ( err ) {
45- error . value = err instanceof Error ? err . message : 'setup.errors.connectionFailed' ;
45+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
46+ } catch ( err : any ) { // Modified
47+ if ( err && err . isCustomError && err . i18nKey === 'setup.errors.failedToConnectWithAddress' ) {
48+ error . value = err . i18nKey ;
49+ errorAddress . value = err . address ;
50+ } else {
51+ // Fallback for other errors
52+ error . value = err instanceof Error ? err . message : 'setup.errors.connectionFailed' ;
53+ errorAddress . value = null ; // Clear if not our specific error
54+ }
4655 return false ;
4756 } finally {
4857 isLoading . value = false ;
@@ -96,6 +105,7 @@ export const useDatabaseStore = defineStore('database', () => {
96105 dialect,
97106 isLoading,
98107 error,
108+ errorAddress, // Added
99109 setupCompleted,
100110
101111 // Computed
Original file line number Diff line number Diff line change 7676 <AlertCircle class =" h-4 w-4" />
7777 <AlertTitle >{{ $t('setup.errors.title') }}</AlertTitle >
7878 <AlertDescription >
79- {{ getErrorMessage(databaseStore.error) }}
79+ {{ getErrorMessage(databaseStore.error, databaseStore.errorAddress ) }}
8080 </AlertDescription >
8181 </Alert >
8282
@@ -187,13 +187,18 @@ function goToLogin() {
187187}
188188
189189// Function to get translated error message
190- function getErrorMessage(error : string ): string {
191- // Check if error is a translation key
192- if (error .startsWith (' setup.errors.' )) {
193- return t (error );
190+ function getErrorMessage(errorKey : string | null , address : string | null ): string {
191+ if (! errorKey ) return ' ' ; // Handle null errorKey
192+
193+ if (errorKey === ' setup.errors.failedToConnectWithAddress' && address ) {
194+ return t (errorKey , { address });
195+ }
196+ // Check if error is a translation key (existing logic)
197+ if (errorKey .startsWith (' setup.errors.' )) {
198+ return t (errorKey );
194199 }
195200 // Return the error as-is if it's not a translation key
196- return error ;
201+ return errorKey ;
197202}
198203
199204// Check database status on component mount
You can’t perform that action at this time.
0 commit comments