mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2024-11-23 00:03:07 +00:00
error handling improvements
This commit is contained in:
parent
f9369ec204
commit
f4c8ab0b5a
3 changed files with 29 additions and 12 deletions
|
@ -76,7 +76,7 @@ export default class extends Vue {
|
|||
public doors: Door[] = [];
|
||||
|
||||
private load_doors(): Promise<void | DoorsSaved> {
|
||||
return this.$advent22.api_get<DoorsSaved>("/general/doors").then((data) => {
|
||||
return this.$advent22.api_get<DoorsSaved>("general/doors").then((data) => {
|
||||
this.doors.length = 0;
|
||||
|
||||
for (const value of data) {
|
||||
|
@ -96,18 +96,22 @@ export default class extends Vue {
|
|||
data.push(door.save());
|
||||
}
|
||||
|
||||
return this.$advent22.api_put("/general/doors", data);
|
||||
return this.$advent22.api_put("general/doors", data);
|
||||
}
|
||||
|
||||
public mounted(): void {
|
||||
this.load_doors().catch((reason) => alert(`Fehler: ${reason}`));
|
||||
this.load_doors().catch(([reason, endpoint]) => {
|
||||
alert(`Fehler: ${reason} in ${endpoint}`);
|
||||
});
|
||||
}
|
||||
|
||||
public on_download() {
|
||||
if (confirm("Aktuelle Änderungen verwerfen und Status vom Server laden?")) {
|
||||
this.load_doors()
|
||||
.then(() => alert("Erfolgeich!"))
|
||||
.catch((reason) => alert(`Fehler: ${reason}`));
|
||||
.catch(([reason, endpoint]) => {
|
||||
alert(`Fehler: ${reason} in ${endpoint}`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,7 +125,13 @@ export default class extends Vue {
|
|||
public on_upload() {
|
||||
if (confirm("Aktuelle Änderungen an den Server schicken?")) {
|
||||
this.save_doors()
|
||||
.then(() => {
|
||||
this.load_doors()
|
||||
.then(() => alert("Erfolgeich!"))
|
||||
.catch(([reason, endpoint]) =>
|
||||
alert(`Fehler: ${reason} in ${endpoint}`),
|
||||
);
|
||||
})
|
||||
.catch((reason) => alert(`Fehler: ${reason}`));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,12 +30,19 @@ export default class extends Vue {
|
|||
.catch(([reason]) => {
|
||||
let msg = "Unbekannter Fehler, bitte wiederholen!";
|
||||
|
||||
if (
|
||||
reason instanceof AxiosError &&
|
||||
reason.response !== undefined &&
|
||||
reason.response.status === 401
|
||||
) {
|
||||
if (reason instanceof AxiosError) {
|
||||
if (reason.code === "ECONNABORTED") {
|
||||
// API unerreichbar
|
||||
msg = "API antwortet nicht, bitte später wiederholen!";
|
||||
} else if (reason.response !== undefined) {
|
||||
if (reason.response.status === 401) {
|
||||
// 401 UNAUTHORIZED
|
||||
msg = "Netter Versuch :)";
|
||||
} else if (reason.response.status === 422) {
|
||||
// 422 UNPROCESSABLE ENTITY
|
||||
msg = "Türchen ist kaputt, bitte Admin benachrichtigen!";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.$emit("doorFailure", msg);
|
||||
|
|
|
@ -78,7 +78,7 @@ export class Advent22 {
|
|||
if (typeof reader.result === "string") {
|
||||
resolve(reader.result);
|
||||
} else {
|
||||
reject([endpoint, "failed data url"]);
|
||||
reject(["failed data url", endpoint]);
|
||||
}
|
||||
};
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue