forked from jsnbuchanan/crowd-funder-for-time-pwa
guard against another set of errors when deleting an image
This commit is contained in:
@@ -202,35 +202,61 @@ export default class GiftedDetails extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async deleteImage() {
|
async deleteImage() {
|
||||||
const identity = await libsUtil.getIdentity(this.activeDid);
|
try {
|
||||||
const token = await accessToken(identity);
|
const identity = await libsUtil.getIdentity(this.activeDid);
|
||||||
const response = await this.axios.delete(
|
const token = await accessToken(identity);
|
||||||
DEFAULT_IMAGE_API_SERVER + "/image/" + encodeURIComponent(this.imageUrl),
|
const response = await this.axios.delete(
|
||||||
{
|
DEFAULT_IMAGE_API_SERVER +
|
||||||
headers: {
|
"/image/" +
|
||||||
Authorization: `Bearer ${token}`,
|
encodeURIComponent(this.imageUrl),
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
if (response.status === 204) {
|
|
||||||
// don't bother with a notification
|
|
||||||
// (either they'll simply continue or they're canceling and going back)
|
|
||||||
} else {
|
|
||||||
console.error("Error deleting image:", response);
|
|
||||||
this.$notify(
|
|
||||||
{
|
{
|
||||||
group: "alert",
|
headers: {
|
||||||
type: "danger",
|
Authorization: `Bearer ${token}`,
|
||||||
title: "Error",
|
},
|
||||||
text: "There was an error deleting the image.",
|
|
||||||
},
|
},
|
||||||
5000,
|
|
||||||
);
|
);
|
||||||
// keep the imageUrl in localStorage so the user can try again if they want
|
if (response.status === 204) {
|
||||||
return;
|
// don't bother with a notification
|
||||||
|
// (either they'll simply continue or they're canceling and going back)
|
||||||
|
} else {
|
||||||
|
console.error("Non-success deleting image:", response);
|
||||||
|
this.$notify(
|
||||||
|
{
|
||||||
|
group: "alert",
|
||||||
|
type: "danger",
|
||||||
|
title: "Error",
|
||||||
|
text: "There was a problem deleting the image.",
|
||||||
|
},
|
||||||
|
5000,
|
||||||
|
);
|
||||||
|
// keep the imageUrl in localStorage so the user can try again if they want
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
localStorage.removeItem("imageUrl");
|
||||||
|
this.imageUrl = "";
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error deleting image:", error);
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
if ((error as any).response.status === 404) {
|
||||||
|
console.log("The image was already deleted:", error);
|
||||||
|
|
||||||
|
localStorage.removeItem("imageUrl");
|
||||||
|
this.imageUrl = "";
|
||||||
|
|
||||||
|
// it already doesn't exist so we won't say anything to the user
|
||||||
|
} else {
|
||||||
|
this.$notify(
|
||||||
|
{
|
||||||
|
group: "alert",
|
||||||
|
type: "danger",
|
||||||
|
title: "Error",
|
||||||
|
text: "There was an error deleting the image.",
|
||||||
|
},
|
||||||
|
5000,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
localStorage.removeItem("imageUrl");
|
|
||||||
this.imageUrl = "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async confirm() {
|
async confirm() {
|
||||||
|
|||||||
Reference in New Issue
Block a user