aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZero~Informatique2020-09-12 06:26:39 +0200
committerG.Fouet2020-09-12 23:19:44 +0200
commit7a8eba922ad34182628f80cf2496d8654abe91e6 (patch)
tree2428f0d7b10896557ddcdfdd6e00f787d9ad1c58
parent836a67bf6455612af4e6e46450caf5f3b88b8edb (diff)
downloadldgallery-7a8eba922ad34182628f80cf2496d8654abe91e6.tar.gz
viewer: improved network errors handling
-rw-r--r--viewer/src/store/galleryStore.ts15
-rw-r--r--viewer/src/views/MainLayout.vue4
2 files changed, 13 insertions, 6 deletions
diff --git a/viewer/src/store/galleryStore.ts b/viewer/src/store/galleryStore.ts
index b672551..5d599aa 100644
--- a/viewer/src/store/galleryStore.ts
+++ b/viewer/src/store/galleryStore.ts
@@ -85,20 +85,22 @@ export default class GalleryStore extends VuexModule {
85 85
86 // Fetches the gallery's JSON config 86 // Fetches the gallery's JSON config
87 @action async fetchConfig() { 87 @action async fetchConfig() {
88 return fetch(`${process.env.VUE_APP_DATA_URL}${GalleryStore.getUrlConfig()}`, { cache: "no-cache" }) 88 await fetch(`${process.env.VUE_APP_DATA_URL}${GalleryStore.getUrlConfig()}`, { cache: "no-cache" })
89 .then(response => response.json()) 89 .then(GalleryStore.responseToJson)
90 .then(this.setConfig); 90 .then(this.setConfig);
91 return this.config!;
91 } 92 }
92 93
93 // Fetches the gallery's JSON metadata 94 // Fetches the gallery's JSON metadata
94 @action async fetchGalleryItems() { 95 @action async fetchGalleryItems() {
95 const root = this.config?.galleryRoot ?? ""; 96 const root = this.config?.galleryRoot ?? "";
96 const index = this.config?.galleryIndex ?? "index.json"; 97 const index = this.config?.galleryIndex ?? "index.json";
97 return fetch(`${process.env.VUE_APP_DATA_URL}${root}${index}`, { cache: "no-cache" }) 98 await fetch(`${process.env.VUE_APP_DATA_URL}${root}${index}`, { cache: "no-cache" })
98 .then(response => response.json()) 99 .then(GalleryStore.responseToJson)
99 .then(this.setGalleryIndex) 100 .then(this.setGalleryIndex)
100 .then(this.indexTags) 101 .then(this.indexTags)
101 .then(this.indexTagCategories); 102 .then(this.indexTagCategories);
103 return this.galleryIndex!;
102 } 104 }
103 105
104 // Indexes the gallery 106 // Indexes the gallery
@@ -128,4 +130,9 @@ export default class GalleryStore extends VuexModule {
128 if (search.length > 1) return search.substr(1) + ".json"; 130 if (search.length > 1) return search.substr(1) + ".json";
129 return "config.json"; 131 return "config.json";
130 } 132 }
133
134 private static responseToJson(response: Response) {
135 if (!response.ok) throw new Error(`${response.status}: ${response.statusText}`);
136 return response.json();
137 }
131} 138}
diff --git a/viewer/src/views/MainLayout.vue b/viewer/src/views/MainLayout.vue
index 21c9cb6..d9ae954 100644
--- a/viewer/src/views/MainLayout.vue
+++ b/viewer/src/views/MainLayout.vue
@@ -70,12 +70,12 @@ export default class MainLayout extends Vue {
70 } 70 }
71 71
72 get isReady() { 72 get isReady() {
73 return !this.isLoading && this.$galleryStore.currentPath !== null; 73 return !this.isLoading && this.$galleryStore.config && this.$galleryStore.currentPath !== null;
74 } 74 }
75 75
76 displayError(reason: any) { 76 displayError(reason: any) {
77 this.$buefy.snackbar.open({ 77 this.$buefy.snackbar.open({
78 message: `Error ${reason}`, 78 message: `${reason}`,
79 actionText: "Retry", 79 actionText: "Retry",
80 position: "is-top", 80 position: "is-top",
81 type: "is-danger", 81 type: "is-danger",