Skip to content

Commit 60e627a

Browse files
committed
#RI-5798 - [Regression] 401 error from WS is not handled
1 parent c60d7ca commit 60e627a

File tree

4 files changed

+43
-39
lines changed

4 files changed

+43
-39
lines changed

redisinsight/ui/src/components/global-subscriptions/CommonAppSubscription/CommonAppSubscription.spec.tsx

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -110,34 +110,4 @@ describe('CommonAppSubscription', () => {
110110

111111
unmount()
112112
})
113-
114-
it('should logout if cloud:job:monitor return statusCode=401', () => {
115-
const { unmount } = render(<CommonAppSubscription />)
116-
117-
const mockData: CloudJobInfo = {
118-
id: '4d76ba0c-71d3-4c9c-ada5-a6e5f4102af5',
119-
name: 'CREATE_FREE_SUBSCRIPTION_AND_DATABASE',
120-
status: 'failed',
121-
error: {
122-
message: 'Authorization failed',
123-
statusCode: 401,
124-
error: 'CloudApiUnauthorized',
125-
errorCode: 11001
126-
},
127-
step: 'subscription'
128-
}
129-
130-
socket.on(CloudJobEvents.Monitor, (data: CloudJobInfo) => {
131-
expect(data).toEqual(mockData)
132-
})
133-
134-
socket.socketClient.emit(CloudJobEvents.Monitor, mockData)
135-
136-
const afterRenderActions = [
137-
logoutUser(),
138-
]
139-
expect(store.getActions()).toEqual([...afterRenderActions])
140-
141-
unmount()
142-
})
143113
})

redisinsight/ui/src/components/global-subscriptions/CommonAppSubscription/CommonAppSubscription.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,6 @@ const CommonAppSubscription = () => {
5555

5656
socketRef.current.on(CloudJobEvents.Monitor, (data: CloudJobInfo) => {
5757
const jobName = data.name as unknown
58-
const statusCode = get(data, 'error.statusCode')
59-
60-
if (statusCode === ApiStatusCode.Unauthorized) {
61-
dispatch(logoutUser())
62-
return
63-
}
6458

6559
if (
6660
jobName === CloudJobName.CreateFreeDatabase

redisinsight/ui/src/components/oauth/oauth-jobs/OAuthJobs.spec.tsx

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { cloneDeep } from 'lodash'
33
import { useSelector } from 'react-redux'
44
import { AxiosError } from 'axios'
55
import { cleanup, clearStoreActions, mockedStore, render } from 'uiSrc/utils/test-utils'
6-
import { oauthCloudJobSelector, setJob, setSocialDialogState } from 'uiSrc/slices/oauth/cloud'
6+
import { logoutUser, oauthCloudJobSelector, setJob, setSocialDialogState } from 'uiSrc/slices/oauth/cloud'
77
import { CloudJobStatus, CloudJobName, CloudJobStep } from 'uiSrc/electron/constants'
88
import { addErrorNotification, addInfiniteNotification, removeInfiniteNotification } from 'uiSrc/slices/app/notifications'
99
import { RootState } from 'uiSrc/slices/store'
@@ -203,4 +203,38 @@ describe('OAuthJobs', () => {
203203
clearStoreActions(expectedActions)
204204
)
205205
})
206+
207+
it('should call logoutUser when statusCode is 401', async () => {
208+
const mockDatabaseId = '123'
209+
const error = {
210+
statusCode: 401,
211+
errorCode: CustomErrorCodes.CloudSubscriptionAlreadyExistsFree,
212+
resource: {
213+
databaseId: mockDatabaseId
214+
}
215+
};
216+
(oauthCloudJobSelector as jest.Mock).mockImplementation(() => ({
217+
status: ''
218+
}))
219+
220+
const { rerender } = render(<OAuthJobs />);
221+
222+
(oauthCloudJobSelector as jest.Mock).mockImplementation(() => ({
223+
status: CloudJobStatus.Failed,
224+
error,
225+
}))
226+
227+
rerender(<OAuthJobs />)
228+
229+
const expectedActions = [
230+
logoutUser(),
231+
addInfiniteNotification(INFINITE_MESSAGES.DATABASE_EXISTS()),
232+
setSSOFlow(),
233+
setSocialDialogState(null),
234+
removeInfiniteNotification(InfiniteMessagesIds.oAuthProgress),
235+
]
236+
expect(clearStoreActions(store.getActions())).toEqual(
237+
clearStoreActions(expectedActions)
238+
)
239+
})
206240
})

redisinsight/ui/src/components/oauth/oauth-jobs/OAuthJobs.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { fetchInstancesAction } from 'uiSrc/slices/instances/instances'
88
import {
99
createFreeDbJob,
1010
createFreeDbSuccess,
11+
logoutUser,
1112
oauthCloudJobSelector,
1213
oauthCloudSelector,
1314
setJob,
@@ -18,7 +19,7 @@ import { addErrorNotification, addInfiniteNotification, removeInfiniteNotificati
1819
import { parseCloudOAuthError } from 'uiSrc/utils'
1920
import { INFINITE_MESSAGES, InfiniteMessagesIds } from 'uiSrc/components/notifications/components'
2021
import { TelemetryEvent, sendEventTelemetry } from 'uiSrc/telemetry'
21-
import { BrowserStorageItem, CustomErrorCodes } from 'uiSrc/constants'
22+
import { ApiStatusCode, BrowserStorageItem, CustomErrorCodes } from 'uiSrc/constants'
2223
import { localStorageService } from 'uiSrc/services'
2324
import { setSSOFlow } from 'uiSrc/slices/instances/cloud'
2425

@@ -49,10 +50,15 @@ const OAuthJobs = () => {
4950
break
5051

5152
case CloudJobStatus.Failed:
52-
5353
const errorCode = get(error, 'errorCode', 0) as CustomErrorCodes
5454
const subscriptionId = get(error, 'resource.subscriptionId', 0)
5555
const resources = get(error, 'resource', {}) as CloudImportDatabaseResources
56+
const statusCode = get(error, 'statusCode', 0) as number
57+
58+
if (statusCode === ApiStatusCode.Unauthorized) {
59+
dispatch(logoutUser())
60+
}
61+
5662
// eslint-disable-next-line sonarjs/no-nested-switch
5763
switch (errorCode) {
5864
case CustomErrorCodes.CloudDatabaseAlreadyExistsFree:

0 commit comments

Comments
 (0)