Skip to content

Commit 913e144

Browse files
show errors when using backup in web
1 parent 6697ab4 commit 913e144

File tree

4 files changed

+66
-65
lines changed

4 files changed

+66
-65
lines changed

web_client/src/api/options.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,27 @@ export const updateSoftware = async (): Promise<{ message: string }> => {
5555
};
5656

5757
export const createBackup = async (): Promise<{ data: Blob; fileName: string }> => {
58-
const response = await axiosInstance.get(`${optionsUrl}/backup`, {
59-
responseType: 'blob',
60-
});
58+
try {
59+
const response = await axiosInstance.get(`${optionsUrl}/backup`, {
60+
responseType: 'blob',
61+
});
6162

62-
const contentDisposition = response.headers['content-disposition'];
63-
let fileName = 'backup.zip'; // fallback filename
63+
const contentDisposition = response.headers['content-disposition'];
64+
let fileName = 'backup.zip'; // fallback filename
6465

65-
if (contentDisposition) {
66-
const match = contentDisposition.match(/filename="(.+?)"/);
67-
if (match?.[1]) {
68-
fileName = match[1];
66+
if (contentDisposition) {
67+
const match = contentDisposition.match(/filename="(.+?)"/);
68+
if (match?.[1]) fileName = match[1];
6969
}
70+
return { data: response.data, fileName };
71+
} catch (error: any) {
72+
if (error instanceof Blob) {
73+
const text = await error.text();
74+
const json = JSON.parse(text);
75+
throw new Error(json.detail || 'An error occurred while creating the backup');
76+
}
77+
throw error;
7078
}
71-
72-
return { data: response.data, fileName };
7379
};
7480

7581
export const uploadBackup = async (file: File): Promise<{ message: string }> => {

web_client/src/components/options/OptionWindow.tsx

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,34 +38,27 @@ const OptionWindow = () => {
3838
};
3939

4040
const getBackupClick = async () => {
41-
try {
42-
const { data, fileName } = await createBackup();
43-
const options = {
44-
suggestedName: fileName,
45-
types: [
46-
{
47-
description: 'Backup Files',
48-
accept: { 'application/octet-stream': ['.zip'] },
49-
},
50-
],
51-
};
52-
const fileHandle = await window.showSaveFilePicker(options);
53-
const writable = await fileHandle.createWritable();
54-
await writable.write(new Blob([data], { type: 'application/octet-stream' }));
55-
await writable.close();
56-
} catch (error) {
57-
console.error('Error saving backup:', error);
58-
}
41+
const { data, fileName } = await createBackup();
42+
const options = {
43+
suggestedName: fileName,
44+
types: [
45+
{
46+
description: 'Backup Files',
47+
accept: { 'application/octet-stream': ['.zip'] },
48+
},
49+
],
50+
};
51+
const fileHandle = await window.showSaveFilePicker(options);
52+
const writable = await fileHandle.createWritable();
53+
await writable.write(new Blob([data], { type: 'application/octet-stream' }));
54+
await writable.close();
55+
return Promise.resolve(t('options.backupSavedSuccessfully', { fileName: fileHandle.name }));
5956
};
6057

6158
const uploadBackupClick = async () => {
6259
let file = undefined;
63-
try {
64-
const [fileHandle] = await window.showOpenFilePicker();
65-
file = await fileHandle.getFile();
66-
} catch {
67-
return;
68-
}
60+
const [fileHandle] = await window.showOpenFilePicker();
61+
file = await fileHandle.getFile();
6962
return uploadBackup(file);
7063
};
7164

web_client/src/locales/de/translation.json

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,28 +68,29 @@
6868
"adjustHeader": "Füllstand der Flasche anpassen, Maximum ist {{maximum}}"
6969
},
7070
"options": {
71-
"cleaning": "Reinigung",
71+
"addons": "Addons",
72+
"adjustTime": "Zeit Anpassen",
73+
"backup": "Sicherung",
74+
"backupSavedSuccessfully": "Backup wurde erfolgreich unter: {{fileName}} gespeichert",
7275
"calibration": "Kalibrierung",
76+
"cleaning": "Reinigung",
77+
"cleaningTheMachine": "Reinigung der Machine",
7378
"configuration": "Konfiguration",
7479
"data": "Daten",
75-
"backup": "Sicherung",
76-
"restore": "Wiederherstellen",
77-
"reboot": "Neustart",
78-
"shutdown": "Herunterfahren",
79-
"logs": "Logs",
80-
"updateSystem": "System aktualisieren",
81-
"systemResourceUsage": "System Ressourcen Auslastung",
82-
"updateCocktailBerry": "CocktailBerry Software aktualisieren",
83-
"wifi": "WLAN",
8480
"internetCheck": "Internetprüfung",
85-
"addons": "Addons",
86-
"adjustTime": "Zeit Anpassen",
8781
"issues": "Probleme",
88-
"cleaningTheMachine": "Reinigung der Machine",
89-
"startCleaningProgram": "Möchtest du das Reinigungsprogramm starten?",
82+
"logs": "Logs",
83+
"reboot": "Neustart",
9084
"rebootTheSystem": "Möchtest du das System neu starten?",
85+
"restore": "Wiederherstellen",
86+
"shutdown": "Herunterfahren",
9187
"shutdownTheSystem": "Möchtest du das System herunterfahren?",
92-
"updateTheSystem": "Möchtest du das System aktualisieren?"
88+
"startCleaningProgram": "Möchtest du das Reinigungsprogramm starten?",
89+
"systemResourceUsage": "System Ressourcen Auslastung",
90+
"updateCocktailBerry": "CocktailBerry Software aktualisieren",
91+
"updateSystem": "System aktualisieren",
92+
"updateTheSystem": "Möchtest du das System aktualisieren?",
93+
"wifi": "WLAN"
9394
},
9495
"calibration": {
9596
"pumpCalibrationProgram": "Pumpen Kalibrieren",

web_client/src/locales/en/translation.json

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,28 +68,29 @@
6868
"adjustHeader": "Adjust the fill level of the bottle, maximum is {{maximum}}"
6969
},
7070
"options": {
71-
"cleaning": "Cleaning",
71+
"addons": "Addons",
72+
"adjustTime": "Adjust Time",
73+
"backup": "Backup",
74+
"backupSavedSuccessfully": "Backup was saved at: {{fileName}}",
7275
"calibration": "Calibration",
76+
"cleaning": "Cleaning",
77+
"cleaningTheMachine": "Cleaning the Machine",
7378
"configuration": "Configuration",
7479
"data": "Data",
75-
"backup": "Backup",
76-
"restore": "Restore",
77-
"reboot": "Reboot",
78-
"shutdown": "Shutdown",
79-
"logs": "Logs",
80-
"updateSystem": "Update System",
81-
"systemResourceUsage": "System Resource Usage",
82-
"updateCocktailBerry": "Update CocktailBerry Software",
83-
"wifi": "WiFi",
8480
"internetCheck": "Internet Check",
85-
"addons": "Addons",
86-
"adjustTime": "Adjust Time",
8781
"issues": "Issues",
88-
"cleaningTheMachine": "Cleaning the Machine",
89-
"startCleaningProgram": "Do you want to start the Cleaning Program?",
82+
"logs": "Logs",
83+
"reboot": "Reboot",
9084
"rebootTheSystem": "Do you want to reboot the System?",
85+
"restore": "Restore",
86+
"shutdown": "Shutdown",
9187
"shutdownTheSystem": "Do you want to shutdown the System?",
92-
"updateTheSystem": "Do you want to update the System?"
88+
"startCleaningProgram": "Do you want to start the Cleaning Program?",
89+
"systemResourceUsage": "System Resource Usage",
90+
"updateCocktailBerry": "Update CocktailBerry Software",
91+
"updateSystem": "Update System",
92+
"updateTheSystem": "Do you want to update the System?",
93+
"wifi": "WiFi"
9394
},
9495
"calibration": {
9596
"pumpCalibrationProgram": "Pump Calibration Program",

0 commit comments

Comments
 (0)