diff --git a/src/components/TheConnectingDialog.vue b/src/components/TheConnectingDialog.vue index d32bdd7c9..68bff8c66 100644 --- a/src/components/TheConnectingDialog.vue +++ b/src/components/TheConnectingDialog.vue @@ -1,35 +1,30 @@ - - @@ -52,10 +47,6 @@ export default class TheConnectingDialog extends Mixins(BaseMixin, ThemeMixin) { counter = 0 - get protocol() { - return this.$store.state.socket.protocol - } - get hostname() { return this.$store.state.socket.hostname } @@ -94,6 +85,10 @@ export default class TheConnectingDialog extends Mixins(BaseMixin, ThemeMixin) { return this.formatHostname } + get connectionFailedMessage() { + return this.$store.state.socket.connectionFailedMessage ?? null + } + reconnect() { this.counter++ this.$store.dispatch('socket/setData', { connectingFailed: false }) diff --git a/src/locales/en.json b/src/locales/en.json index b12da347f..9cafae33c 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -154,6 +154,7 @@ "CannotConnectTo": "Cannot connect to Moonraker ({host}).", "CheckMoonrakerLog": "If this message appears repeatedly, please have a look in the log file located at:", "Connecting": "Connecting to {host}", + "ErrorMessage": "Error message: {message}", "Failed": "Connection failed", "Initializing": "Initializing", "TryAgain": "try again" diff --git a/src/plugins/webSocketClient.ts b/src/plugins/webSocketClient.ts index 1208bb7cb..6e4820240 100644 --- a/src/plugins/webSocketClient.ts +++ b/src/plugins/webSocketClient.ts @@ -36,6 +36,11 @@ export class WebSocketClient { window.console.error(`Response Error: ${data.error.message} (${wait?.action ?? 'no action'})`) } + if (data.error.message === 'Unauthorized' && wait?.action === 'server/setConnectionId') { + this.close() + this.store?.dispatch('socket/setConnectionFailed', data.error.message) + } + if (wait?.id) { const modulename = wait.action?.split('/')[1] ?? null diff --git a/src/store/socket/actions.ts b/src/store/socket/actions.ts index 0a207d48b..24263cd2d 100644 --- a/src/store/socket/actions.ts +++ b/src/store/socket/actions.ts @@ -173,4 +173,8 @@ export const actions: ActionTree = { reportDebug(_, payload) { window.console.log(payload) }, + + setConnectionFailed({ commit }, payload) { + commit('setDisconnected', payload) + }, } diff --git a/src/store/socket/index.ts b/src/store/socket/index.ts index c50c7bc7a..f9f1a8681 100644 --- a/src/store/socket/index.ts +++ b/src/store/socket/index.ts @@ -20,6 +20,7 @@ export const getDefaultState = (): SocketState => { isConnected: false, isConnecting: false, connectingFailed: false, + connectionFailedMessage: null, loadings: [], initializationList: ['server'], connection_id: null, diff --git a/src/store/socket/mutations.ts b/src/store/socket/mutations.ts index 9399eb169..96ed25d60 100644 --- a/src/store/socket/mutations.ts +++ b/src/store/socket/mutations.ts @@ -16,11 +16,13 @@ export const mutations: MutationTree = { Vue.set(state, 'connectingFailed', false) }, - setDisconnected(state) { + setDisconnected(state, message?: string) { Vue.set(state, 'isConnected', false) Vue.set(state, 'isConnecting', false) Vue.set(state, 'connectingFailed', true) Vue.set(state, 'connection_id', null) + + if (message) Vue.set(state, 'connectionFailedMessage', message) }, setData(state, payload) { diff --git a/src/store/socket/types.ts b/src/store/socket/types.ts index c2675e784..9c8d0c1ee 100644 --- a/src/store/socket/types.ts +++ b/src/store/socket/types.ts @@ -7,6 +7,7 @@ export interface SocketState { isConnected: boolean isConnecting: boolean connectingFailed: boolean + connectionFailedMessage: string | null loadings: string[] initializationList: string[] connection_id: number | null