fix(ui): improve schema parsing error handling

This commit is contained in:
psychedelicious 2023-04-27 14:54:54 +10:00
parent 2b5ccdc55f
commit a8cec4c7e6
3 changed files with 21 additions and 14 deletions

View File

@ -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;

View File

@ -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;
});
},

View File

@ -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;
}
);