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[] = [];
|
public doors: Door[] = [];
|
||||||
|
|
||||||
private load_doors(): Promise<void | DoorsSaved> {
|
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;
|
this.doors.length = 0;
|
||||||
|
|
||||||
for (const value of data) {
|
for (const value of data) {
|
||||||
|
@ -96,18 +96,22 @@ export default class extends Vue {
|
||||||
data.push(door.save());
|
data.push(door.save());
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.$advent22.api_put("/general/doors", data);
|
return this.$advent22.api_put("general/doors", data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public mounted(): void {
|
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() {
|
public on_download() {
|
||||||
if (confirm("Aktuelle Änderungen verwerfen und Status vom Server laden?")) {
|
if (confirm("Aktuelle Änderungen verwerfen und Status vom Server laden?")) {
|
||||||
this.load_doors()
|
this.load_doors()
|
||||||
.then(() => alert("Erfolgeich!"))
|
.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() {
|
public on_upload() {
|
||||||
if (confirm("Aktuelle Änderungen an den Server schicken?")) {
|
if (confirm("Aktuelle Änderungen an den Server schicken?")) {
|
||||||
this.save_doors()
|
this.save_doors()
|
||||||
.then(() => alert("Erfolgeich!"))
|
.then(() => {
|
||||||
|
this.load_doors()
|
||||||
|
.then(() => alert("Erfolgeich!"))
|
||||||
|
.catch(([reason, endpoint]) =>
|
||||||
|
alert(`Fehler: ${reason} in ${endpoint}`),
|
||||||
|
);
|
||||||
|
})
|
||||||
.catch((reason) => alert(`Fehler: ${reason}`));
|
.catch((reason) => alert(`Fehler: ${reason}`));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,12 +30,19 @@ export default class extends Vue {
|
||||||
.catch(([reason]) => {
|
.catch(([reason]) => {
|
||||||
let msg = "Unbekannter Fehler, bitte wiederholen!";
|
let msg = "Unbekannter Fehler, bitte wiederholen!";
|
||||||
|
|
||||||
if (
|
if (reason instanceof AxiosError) {
|
||||||
reason instanceof AxiosError &&
|
if (reason.code === "ECONNABORTED") {
|
||||||
reason.response !== undefined &&
|
// API unerreichbar
|
||||||
reason.response.status === 401
|
msg = "API antwortet nicht, bitte später wiederholen!";
|
||||||
) {
|
} else if (reason.response !== undefined) {
|
||||||
msg = "Netter Versuch :)";
|
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);
|
this.$emit("doorFailure", msg);
|
||||||
|
|
|
@ -78,7 +78,7 @@ export class Advent22 {
|
||||||
if (typeof reader.result === "string") {
|
if (typeof reader.result === "string") {
|
||||||
resolve(reader.result);
|
resolve(reader.result);
|
||||||
} else {
|
} else {
|
||||||
reject([endpoint, "failed data url"]);
|
reject(["failed data url", endpoint]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue