fix: improve error handling for user settings retrieval in GET and settings store
This commit is contained in:
@@ -53,10 +53,7 @@ export async function GET(request: NextRequest) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const settings = await loadUserSettings(username, serverUrl);
|
const settings = await loadUserSettings(username, serverUrl);
|
||||||
if (!settings) {
|
return NextResponse.json({ settings: settings || null });
|
||||||
return NextResponse.json({ error: 'No settings found' }, { status: 404 });
|
|
||||||
}
|
|
||||||
return NextResponse.json({ settings });
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = error instanceof Error ? error.message : 'Unknown error';
|
const message = error instanceof Error ? error.message : 'Unknown error';
|
||||||
const code = (error as NodeJS.ErrnoException).code;
|
const code = (error as NodeJS.ErrnoException).code;
|
||||||
|
|||||||
@@ -510,10 +510,14 @@ export const useSettingsStore = create<SettingsState>()(
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
syncLog('No server settings found (status', res.status + ')');
|
syncLog('Settings fetch failed (status', res.status + ')');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const { settings } = await res.json();
|
const { settings } = await res.json();
|
||||||
|
if (!settings) {
|
||||||
|
syncLog('No server settings found yet');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (settings && typeof settings === 'object') {
|
if (settings && typeof settings === 'object') {
|
||||||
isLoadingFromServer = true;
|
isLoadingFromServer = true;
|
||||||
get().importSettings(JSON.stringify(settings));
|
get().importSettings(JSON.stringify(settings));
|
||||||
|
|||||||
Reference in New Issue
Block a user