Browse Source

guard against another set of errors when deleting an image

photo-upload
Trent Larson 8 months ago
parent
commit
ae857f4c8f
  1. 32
      src/views/GiftedDetails.vue

32
src/views/GiftedDetails.vue

@ -202,10 +202,13 @@ export default class GiftedDetails extends Vue {
} }
async deleteImage() { async deleteImage() {
try {
const identity = await libsUtil.getIdentity(this.activeDid); const identity = await libsUtil.getIdentity(this.activeDid);
const token = await accessToken(identity); const token = await accessToken(identity);
const response = await this.axios.delete( const response = await this.axios.delete(
DEFAULT_IMAGE_API_SERVER + "/image/" + encodeURIComponent(this.imageUrl), DEFAULT_IMAGE_API_SERVER +
"/image/" +
encodeURIComponent(this.imageUrl),
{ {
headers: { headers: {
Authorization: `Bearer ${token}`, Authorization: `Bearer ${token}`,
@ -216,21 +219,44 @@ export default class GiftedDetails extends Vue {
// don't bother with a notification // don't bother with a notification
// (either they'll simply continue or they're canceling and going back) // (either they'll simply continue or they're canceling and going back)
} else { } else {
console.error("Error deleting image:", response); console.error("Non-success deleting image:", response);
this.$notify( this.$notify(
{ {
group: "alert", group: "alert",
type: "danger", type: "danger",
title: "Error", title: "Error",
text: "There was an error deleting the image.", text: "There was a problem deleting the image.",
}, },
5000, 5000,
); );
// keep the imageUrl in localStorage so the user can try again if they want // keep the imageUrl in localStorage so the user can try again if they want
return; 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"); localStorage.removeItem("imageUrl");
this.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,
);
}
}
} }
async confirm() { async confirm() {

Loading…
Cancel
Save