surface usage errors for cnet and upscale, handle clearing cnet if error occurs

This commit is contained in:
Mary Hipp 2023-09-27 11:59:44 -04:00 committed by psychedelicious
parent 807c6b41c5
commit 40ed218c26
3 changed files with 54 additions and 3 deletions

View File

@ -1,7 +1,11 @@
import { logger } from 'app/logging/logger';
import { parseify } from 'common/util/serialize';
import { controlNetImageProcessed } from 'features/controlNet/store/actions';
import { controlNetProcessedImageChanged } from 'features/controlNet/store/controlNetSlice';
import {
clearPendingControlImages,
controlNetImageChanged,
controlNetProcessedImageChanged,
} from 'features/controlNet/store/controlNetSlice';
import { SAVE_IMAGE } from 'features/nodes/util/graphBuilders/constants';
import { addToast } from 'features/system/store/systemSlice';
import { t } from 'i18next';
@ -11,6 +15,7 @@ import { isImageOutput } from 'services/api/guards';
import { Graph, ImageDTO } from 'services/api/types';
import { socketInvocationComplete } from 'services/events/actions';
import { startAppListening } from '..';
import { FetchBaseQueryError } from '@reduxjs/toolkit/dist/query';
export const addControlNetImageProcessedListener = () => {
startAppListening({
@ -105,8 +110,31 @@ export const addControlNetImageProcessedListener = () => {
})
);
}
} catch {
} catch (error) {
log.error({ graph: parseify(graph) }, t('queue.graphFailedToQueue'));
// handle usage-related errors
if (error instanceof Object) {
if ('data' in error && 'status' in error) {
if (error.status === 403) {
const detail = (error.data as any)?.detail || 'Unknown Error';
dispatch(
addToast({
title: t('queue.graphFailedToQueue'),
status: 'error',
description: detail,
duration: 15000,
})
);
dispatch(clearPendingControlImages());
dispatch(
controlNetImageChanged({ controlNetId, controlImage: null })
);
return;
}
}
}
dispatch(
addToast({
title: t('queue.graphFailedToQueue'),

View File

@ -44,8 +44,27 @@ export const addUpscaleRequestedListener = () => {
{ enqueueResult: parseify(enqueueResult) },
t('queue.graphQueued')
);
} catch {
} catch (error) {
log.error({ graph: parseify(graph) }, t('queue.graphFailedToQueue'));
// handle usage-related errors
if (error instanceof Object) {
if ('data' in error && 'status' in error) {
if (error.status === 403) {
const detail = (error.data as any)?.detail || 'Unknown Error';
dispatch(
addToast({
title: t('queue.graphFailedToQueue'),
status: 'error',
description: detail,
duration: 15000,
})
);
return;
}
}
}
dispatch(
addToast({
title: t('queue.graphFailedToQueue'),

View File

@ -410,6 +410,9 @@ export const controlNetSlice = createSlice({
state.isIPAdapterEnabled = false;
state.ipAdapterInfo = { ...initialIPAdapterState };
},
clearPendingControlImages: (state) => {
state.pendingControlImages = [];
},
},
extraReducers: (builder) => {
builder.addCase(controlNetImageProcessed, (state, action) => {
@ -474,6 +477,7 @@ export const {
ipAdapterBeginStepPctChanged,
ipAdapterEndStepPctChanged,
ipAdapterStateReset,
clearPendingControlImages,
} = controlNetSlice.actions;
export default controlNetSlice.reducer;