diff --git a/src/store/server/spoolman/actions.ts b/src/store/server/spoolman/actions.ts index 510c23c75..1f3eaf2d5 100644 --- a/src/store/server/spoolman/actions.ts +++ b/src/store/server/spoolman/actions.ts @@ -3,6 +3,18 @@ import { ActionTree } from 'vuex' import { RootState } from '@/store/types' import { ServerSpoolmanState } from '@/store/server/spoolman/types' +function convertV2response(payload: { error?: { message: string } | null; response: any }) { + if ((payload.error?.message ?? null) !== null) { + Vue.$toast.error(payload.error?.message ?? 'unknown spoolman error') + return null + } + + // if the response is v2, we need to get the response into the payload + if ('response' in payload) return payload.response + + return payload +} + export const actions: ActionTree = { reset({ commit }) { commit('reset') @@ -15,6 +27,7 @@ export const actions: ActionTree = { { request_method: 'GET', path: '/v1/info', + use_v2_response: true, }, { action: 'server/spoolman/getInfo' } ) @@ -23,6 +36,7 @@ export const actions: ActionTree = { { request_method: 'GET', path: '/v1/health', + use_v2_response: true, }, { action: 'server/spoolman/getHealth' } ) @@ -31,6 +45,7 @@ export const actions: ActionTree = { { request_method: 'GET', path: '/v1/vendor', + use_v2_response: true, }, { action: 'server/spoolman/getVendors' } ) @@ -57,6 +72,7 @@ export const actions: ActionTree = { 'server.spoolman.proxy', { request_method: 'GET', + use_v2_response: true, path: `/v1/spool/${payload.spool_id}`, }, { action: 'server/spoolman/getActiveSpool' } @@ -65,29 +81,41 @@ export const actions: ActionTree = { getActiveSpool({ commit }, payload) { if ('requestParams' in payload) delete payload.requestParams + payload = convertV2response(payload) + if (payload === null) return commit('setActiveSpool', payload) }, getHealth({ commit, dispatch }, payload) { delete payload.requestParams - commit('setHealth', payload.status) dispatch('socket/removeInitModule', 'server/spoolman/getHealth', { root: true }) + + payload = convertV2response(payload) + if (payload === null) return + + commit('setHealth', payload.status) }, getInfo({ commit, dispatch }, payload) { delete payload.requestParams - commit('setInfo', payload) dispatch('socket/removeInitModule', 'server/spoolman/getInfo', { root: true }) + payload = convertV2response(payload) + if (payload === null) return + + commit('setInfo', payload) }, getVendors({ commit, dispatch }, payload) { delete payload.requestParams + dispatch('socket/removeInitModule', 'server/spoolman/getVendors', { root: true }) + payload = convertV2response(payload) + if (payload === null) return + commit( 'setVendors', Object.entries(payload).map((value) => value) ) - dispatch('socket/removeInitModule', 'server/spoolman/getVendors', { root: true }) }, refreshSpools({ dispatch }) { @@ -105,10 +133,12 @@ export const actions: ActionTree = { getSpools({ commit, dispatch }, payload) { if ('requestParams' in payload) delete payload.requestParams + dispatch('socket/removeLoading', 'refreshSpools', { root: true }) + payload = convertV2response(payload) + if (payload === null) return + const spools = Object.entries(payload).map((value) => value[1]) commit('setSpools', spools) - - dispatch('socket/removeLoading', 'refreshSpools', { root: true }) }, setActiveSpool(_, id: number | null) {