mirror of
https://github.com/Sebclem/hassio-nextcloud-backup.git
synced 2024-11-22 09:12:58 +01:00
Add some error handling
This commit is contained in:
parent
5f3c59c572
commit
a76b20c199
@ -22,24 +22,19 @@ configRouter.get("/backup", (req, res) => {
|
|||||||
|
|
||||||
configRouter.put("/backup", (req, res) => {
|
configRouter.put("/backup", (req, res) => {
|
||||||
validateBackupConfig(req.body as BackupConfig)
|
validateBackupConfig(req.body as BackupConfig)
|
||||||
.then(
|
.then(() => {
|
||||||
() => {
|
|
||||||
return saveBackupConfig(req.body as BackupConfig);
|
return saveBackupConfig(req.body as BackupConfig);
|
||||||
},
|
})
|
||||||
(error: ValidationError) => {
|
.then(() => {
|
||||||
res.status(400).json(error.details);
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.then(
|
|
||||||
() => {
|
|
||||||
res.status(204).send();
|
res.status(204).send();
|
||||||
},
|
})
|
||||||
() => {
|
.catch((error: ValidationError) => {
|
||||||
res.status(400).json({
|
if (error.details) {
|
||||||
message: "Fail to init cron, please check cron config",
|
res.status(400).json({ type: "validation", errors: error.details });
|
||||||
});
|
} else {
|
||||||
|
res.status(400).json({ type: "cron", errors: [error.message] });
|
||||||
}
|
}
|
||||||
);
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
configRouter.get("/webdav", (req, res) => {
|
configRouter.get("/webdav", (req, res) => {
|
||||||
@ -58,9 +53,9 @@ configRouter.put("/webdav", (req, res) => {
|
|||||||
.catch((error: ValidationError) => {
|
.catch((error: ValidationError) => {
|
||||||
res.status(400);
|
res.status(400);
|
||||||
if (error.details) {
|
if (error.details) {
|
||||||
res.json(error.details);
|
res.json({ type: "validation", errors: error.details });
|
||||||
} else {
|
} else {
|
||||||
res.json(error);
|
res.json({ type: "validation", errors: error });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -26,6 +26,14 @@
|
|||||||
{{ CronModeFriendly[cron.mode] }}
|
{{ CronModeFriendly[cron.mode] }}
|
||||||
<v-spacer></v-spacer>
|
<v-spacer></v-spacer>
|
||||||
<v-fade-transition>
|
<v-fade-transition>
|
||||||
|
<v-chip
|
||||||
|
v-if="errors.includes(cron.id)"
|
||||||
|
color="error"
|
||||||
|
variant="flat"
|
||||||
|
prepend-icon="mdi-alert"
|
||||||
|
>
|
||||||
|
INVALID
|
||||||
|
</v-chip>
|
||||||
<v-chip
|
<v-chip
|
||||||
v-if="!expanded && cron.monthDay != undefined"
|
v-if="!expanded && cron.monthDay != undefined"
|
||||||
append-icon="mdi-calendar"
|
append-icon="mdi-calendar"
|
||||||
@ -186,7 +194,7 @@ import { ref } from "vue";
|
|||||||
|
|
||||||
const expansionPanelModel = ref(undefined);
|
const expansionPanelModel = ref(undefined);
|
||||||
|
|
||||||
defineProps<{ loading: boolean }>();
|
defineProps<{ loading: boolean, errors: string[] }>();
|
||||||
const backupConfigStore = useBackupConfigStore();
|
const backupConfigStore = useBackupConfigStore();
|
||||||
|
|
||||||
function removeCron(id: string) {
|
function removeCron(id: string) {
|
||||||
|
@ -33,6 +33,8 @@
|
|||||||
variant="outlined"
|
variant="outlined"
|
||||||
color="orange"
|
color="orange"
|
||||||
min="1"
|
min="1"
|
||||||
|
:loading="loading"
|
||||||
|
:error-messages="errors.nbrToKeep"
|
||||||
></v-text-field>
|
></v-text-field>
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
@ -66,6 +68,8 @@
|
|||||||
variant="outlined"
|
variant="outlined"
|
||||||
color="orange"
|
color="orange"
|
||||||
min="1"
|
min="1"
|
||||||
|
:loading="loading"
|
||||||
|
:error-messages="errors.nbrToKeep"
|
||||||
></v-text-field>
|
></v-text-field>
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
@ -79,7 +83,7 @@
|
|||||||
import { useBackupConfigStore } from "@/store/backupConfig";
|
import { useBackupConfigStore } from "@/store/backupConfig";
|
||||||
import { storeToRefs } from "pinia";
|
import { storeToRefs } from "pinia";
|
||||||
|
|
||||||
defineProps<{ loading: boolean }>();
|
defineProps<{ loading: boolean, errors: any }>();
|
||||||
const backupConfigStore = useBackupConfigStore();
|
const backupConfigStore = useBackupConfigStore();
|
||||||
const { data } = storeToRefs(backupConfigStore);
|
const { data } = storeToRefs(backupConfigStore);
|
||||||
</script>
|
</script>
|
||||||
|
@ -41,6 +41,8 @@
|
|||||||
density="compact"
|
density="compact"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
color="orange"
|
color="orange"
|
||||||
|
:loading="loading"
|
||||||
|
:error-messages="errors.backupType"
|
||||||
>
|
>
|
||||||
</v-select>
|
</v-select>
|
||||||
</v-col>
|
</v-col>
|
||||||
@ -65,12 +67,12 @@
|
|||||||
</v-row>
|
</v-row>
|
||||||
<v-row dense>
|
<v-row dense>
|
||||||
<v-col>
|
<v-col>
|
||||||
<BackupConfigAutoBackup :loading="loading"></BackupConfigAutoBackup>
|
<BackupConfigAutoBackup :loading="loading" :errors="errors.cron"></BackupConfigAutoBackup>
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
<v-row dense>
|
<v-row dense>
|
||||||
<v-col>
|
<v-col>
|
||||||
<BackupConfigAutoClean :loading="loading"></BackupConfigAutoClean>
|
<BackupConfigAutoClean :loading="loading" :errors=errors></BackupConfigAutoClean>
|
||||||
</v-col>
|
</v-col>
|
||||||
</v-row>
|
</v-row>
|
||||||
<v-row dense>
|
<v-row dense>
|
||||||
@ -105,12 +107,13 @@ const backupConfigStore = useBackupConfigStore();
|
|||||||
const { data } = storeToRefs(backupConfigStore);
|
const { data } = storeToRefs(backupConfigStore);
|
||||||
const errors = ref({
|
const errors = ref({
|
||||||
nameTemplate: [],
|
nameTemplate: [],
|
||||||
username: [],
|
backupType: [],
|
||||||
password: [],
|
nbrToKeep: [],
|
||||||
backupDir: [],
|
backupDir: [],
|
||||||
allowSelfSignedCerts: [],
|
allowSelfSignedCerts: [],
|
||||||
type: [],
|
type: [],
|
||||||
customEndpoint: [],
|
customEndpoint: [],
|
||||||
|
cron: []
|
||||||
});
|
});
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
|
@ -26,13 +26,18 @@ export function useConfigForm(
|
|||||||
.catch(async (reason) => {
|
.catch(async (reason) => {
|
||||||
if (reason instanceof HTTPError) {
|
if (reason instanceof HTTPError) {
|
||||||
const response = await reason.response.json();
|
const response = await reason.response.json();
|
||||||
if (Array.isArray(response)) {
|
if (response["type"] == "validation") {
|
||||||
for (const elem of response) {
|
for (const elem of response["errors"]) {
|
||||||
errorsRef.value[
|
errorsRef.value[
|
||||||
elem.context.key as keyof typeof errorsRef.value
|
elem.context.key as keyof typeof errorsRef.value
|
||||||
] = elem.message;
|
] = elem.message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (response["type"] == "cron") {
|
||||||
|
for (const elem of response["errors"]) {
|
||||||
|
errorsRef.value["cron"].push(elem)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
emit("fail");
|
emit("fail");
|
||||||
|
Loading…
Reference in New Issue
Block a user