Skip to content

Commit 538432d

Browse files
committed
fix: for initial generation show error on main screen (not popup)
1 parent cdad5ef commit 538432d

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

custom/imageGenerator.vue

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@
5757
</div>
5858
</div>
5959

60+
<div v-if="errorMessage" class="absolute flex items-center justify-center w-full h-full z-50 bg-white/80 dark:bg-gray-900/80 rounded-lg">
61+
<div class="pt-20 text-red-500 dark:text-red-400 text-lg font-semibold">
62+
{{ errorMessage }}
63+
</div>
64+
</div>
65+
6066

6167
<div id="gallery" class="relative w-full" data-carousel="static">
6268
<!-- Carousel wrapper -->
@@ -118,7 +124,7 @@
118124
<!-- Modal footer -->
119125
<div class="flex items-center p-4 md:p-5 border-t border-gray-200 rounded-b dark:border-gray-600">
120126
<button type="button" @click="confirmImage"
121-
:disabled="loading"
127+
:disabled="loading || images.length === 0"
122128
class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center
123129
dark:bg-blue-600 dark:hover:bg-blue-700 dark:focus:ring-blue-800
124130
disabled:opacity-50 disabled:cursor-not-allowed"
@@ -248,6 +254,8 @@ const loadingTimer: Ref<number | null> = ref(null);
248254
249255
const historicalRuns: Ref<number[]> = ref([]);
250256
257+
const errorMessage: Ref<string | null> = ref(null);
258+
251259
const historicalAverage: Ref<number | null> = computed(() => {
252260
if (historicalRuns.value.length === 0) return null;
253261
const sum = historicalRuns.value.reduce((a, b) => a + b, 0);
@@ -262,6 +270,7 @@ function formatTime(seconds: number): string {
262270
263271
264272
async function generateImages() {
273+
errorMessage.value = null;
265274
loading.value = true;
266275
loadingTimer.value = 0;
267276
const start = Date.now();
@@ -271,7 +280,8 @@ async function generateImages() {
271280
}, 100);
272281
const currentIndex = caurosel.value?.getActiveItem()?.position || 0;
273282
274-
let resp;
283+
let resp = null;
284+
let error = null;
275285
try {
276286
resp = await callAdminForthApi({
277287
path: `/plugin/${props.meta.pluginInstanceId}/generate_images`,
@@ -287,15 +297,25 @@ async function generateImages() {
287297
historicalRuns.value.push(loadingTimer.value);
288298
clearInterval(ticker);
289299
loadingTimer.value = null;
290-
291-
}
292-
if (resp.error) {
293-
adminforth.alert({
294-
message: $t('Error: {error}', { error: JSON.stringify(resp.error) }),
295-
variant: 'danger',
296-
timeout: 15,
297-
});
298300
loading.value = false;
301+
}
302+
if (resp?.error) {
303+
error = resp.error;
304+
}
305+
if (!resp) {
306+
error = $t('Error generating images, something went wrong');
307+
}
308+
309+
if (error) {
310+
if (images.value.length === 0) {
311+
errorMessage.value = error;
312+
} else {
313+
adminforth.alert({
314+
message: error,
315+
variant: 'danger',
316+
timeout: 'unlimited',
317+
});
318+
}
299319
return;
300320
}
301321

index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,6 @@ getBucketLifecycleConfiguration on bucket ${this.options.s3Bucket} in region ${t
486486
path: `/plugin/${this.pluginInstanceId}/generate_images`,
487487
handler: async ({ body, adminUser, headers }) => {
488488
const { prompt, recordId } = body;
489-
490489
if (this.options.generation.rateLimit?.limit) {
491490
// rate limit
492491
const { error } = RateLimiter.checkRateLimit(

0 commit comments

Comments
 (0)