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