mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
fix(ui): improve schema parsing error handling
This commit is contained in:
parent
2b5ccdc55f
commit
a8cec4c7e6
@ -82,10 +82,19 @@ const nodesSlice = createSlice({
|
||||
shouldShowGraphOverlayChanged: (state, action: PayloadAction<boolean>) => {
|
||||
state.shouldShowGraphOverlay = action.payload;
|
||||
},
|
||||
parsedOpenAPISchema: (state, action: PayloadAction<OpenAPIV3.Document>) => {
|
||||
try {
|
||||
const parsedSchema = parseSchema(action.payload);
|
||||
console.debug('Parsed schema: ', parsedSchema);
|
||||
state.invocationTemplates = parsedSchema;
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
},
|
||||
},
|
||||
extraReducers(builder) {
|
||||
builder.addCase(receivedOpenAPISchema.fulfilled, (state, action) => {
|
||||
state.invocationTemplates = action.payload;
|
||||
state.schema = action.payload;
|
||||
});
|
||||
|
||||
builder.addMatcher(isFulfilledAnyGraphBuilt, (state, action) => {
|
||||
@ -103,6 +112,7 @@ export const {
|
||||
connectionStarted,
|
||||
connectionEnded,
|
||||
shouldShowGraphOverlayChanged,
|
||||
parsedOpenAPISchema,
|
||||
} = nodesSlice.actions;
|
||||
|
||||
export default nodesSlice.reducer;
|
||||
|
@ -19,9 +19,8 @@ import { ProgressImage } from 'services/events/types';
|
||||
import { initialImageSelected } from 'features/parameters/store/generationSlice';
|
||||
import { makeToast } from '../hooks/useToastWatcher';
|
||||
import { sessionCanceled, sessionInvoked } from 'services/thunks/session';
|
||||
import { InvokeTabName } from 'features/ui/store/tabMap';
|
||||
import { receivedModels } from 'services/thunks/model';
|
||||
import { receivedOpenAPISchema } from 'services/thunks/schema';
|
||||
import { parsedOpenAPISchema } from 'features/nodes/store/nodesSlice';
|
||||
|
||||
export type LogLevel = 'info' | 'warning' | 'error';
|
||||
|
||||
@ -546,14 +545,14 @@ export const systemSlice = createSlice({
|
||||
/**
|
||||
* Received available models from the backend
|
||||
*/
|
||||
builder.addCase(receivedModels.fulfilled, (state, action) => {
|
||||
builder.addCase(receivedModels.fulfilled, (state) => {
|
||||
state.wereModelsReceived = true;
|
||||
});
|
||||
|
||||
/**
|
||||
* OpenAPI schema was received and parsed
|
||||
* OpenAPI schema was parsed
|
||||
*/
|
||||
builder.addCase(receivedOpenAPISchema.fulfilled, (state, action) => {
|
||||
builder.addCase(parsedOpenAPISchema, (state) => {
|
||||
state.wasSchemaParsed = true;
|
||||
});
|
||||
},
|
||||
|
@ -1,19 +1,17 @@
|
||||
import { createAsyncThunk } from '@reduxjs/toolkit';
|
||||
import { parseSchema } from 'features/nodes/util/parseSchema';
|
||||
import { parsedOpenAPISchema } from 'features/nodes/store/nodesSlice';
|
||||
import { OpenAPIV3 } from 'openapi-types';
|
||||
|
||||
export const receivedOpenAPISchema = createAsyncThunk(
|
||||
'nodes/receivedOpenAPISchema',
|
||||
async () => {
|
||||
async (_, { dispatch }): Promise<OpenAPIV3.Document> => {
|
||||
const response = await fetch(`openapi.json`);
|
||||
const jsonData = (await response.json()) as OpenAPIV3.Document;
|
||||
const openAPISchema = (await response.json()) as OpenAPIV3.Document;
|
||||
|
||||
console.debug('OpenAPI schema: ', jsonData);
|
||||
console.debug('OpenAPI schema: ', openAPISchema);
|
||||
|
||||
const parsedSchema = parseSchema(jsonData);
|
||||
dispatch(parsedOpenAPISchema(openAPISchema));
|
||||
|
||||
console.debug('Parsed schema: ', parsedSchema);
|
||||
|
||||
return parsedSchema;
|
||||
return openAPISchema;
|
||||
}
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user