Просмотр исходного кода

Maintenance: Fix unhandled exception in app maintenance check.

Dusan Vuckovic 1 год назад
Родитель
Сommit
19454c8d72

+ 20 - 0
app/frontend/shared/composables/__tests__/useAppMaintenanceCheck.spec.ts

@@ -105,4 +105,24 @@ describe('useAppMaintenanceCheck', () => {
       'A newer version of the app is available. Please reload at your earliest.',
     )
   })
+
+  it('does not raise unhandled exceptions if the payload structure is wrong', async (context) => {
+    context.skipConsole = true
+
+    vi.spyOn(console, 'log').mockClear()
+
+    await subscriptionAppMaintenance.next({
+      data: {
+        pushMessages: {
+          title: null,
+          text: null,
+        },
+      },
+    })
+
+    expect(console.log).not.toHaveBeenCalledWith(
+      'Uncaught Exception',
+      new TypeError("Cannot read properties of undefined (reading 'type')"),
+    )
+  })
 })

+ 1 - 1
app/frontend/shared/composables/useAppMaintenanceCheck.ts

@@ -87,7 +87,7 @@ const useAppMaintenanceCheck = (
       useAppMaintenanceSubscription(),
     )
     appMaintenanceSubscription.onResult((result) => {
-      const type = result.data?.appMaintenance.type
+      const type = result.data?.appMaintenance?.type
       let message = notificationMessage
 
       if (!type) {