Skip to content

Commit 854b984

Browse files
authored
Display explicit errors if websocket connection cannot be stablished (#2756)
Signed-off-by: Benjamin Perez <benjamin@bexsoft.net>
1 parent 62fa0e2 commit 854b984

File tree

4 files changed

+56
-14
lines changed

4 files changed

+56
-14
lines changed

portal-ui/src/screens/Console/Buckets/BucketDetails/BrowserHandler.tsx

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { containerForHeader } from "../../Common/FormComponents/common/styleLibr
2626
import ListObjects from "../ListBuckets/Objects/ListObjects/ListObjects";
2727
import { IAM_SCOPES } from "../../../../common/SecureComponent/permissions";
2828
import {
29+
errorInConnection,
2930
newMessage,
3031
resetMessages,
3132
setIsOpeningOD,
@@ -70,7 +71,8 @@ let wsInFlight: boolean = false;
7071

7172
const initWSConnection = (
7273
openCallback?: () => void,
73-
onMessageCallback?: (message: IMessageEvent) => void
74+
onMessageCallback?: (message: IMessageEvent) => void,
75+
connErrorCallback?: (message: string) => void
7476
) => {
7577
if (wsInFlight) {
7678
return;
@@ -104,10 +106,17 @@ const initWSConnection = (
104106

105107
const reconnectFn = () => {
106108
if (errorCounter <= 5) {
107-
initWSConnection(() => {}, onMessageCallback);
109+
initWSConnection(() => {}, onMessageCallback, connErrorCallback);
108110
errorCounter += 1;
109111
} else {
110-
console.error("Websocket not available.");
112+
console.error(
113+
"Websocket not available. Please review that your environment settings are enabled to allow websocket connections and that requests are made from the same origin."
114+
);
115+
if (connErrorCallback) {
116+
connErrorCallback(
117+
"Couldn't establish WebSocket connection. Please review your configuration and try again."
118+
);
119+
}
111120
}
112121
};
113122

@@ -245,6 +254,7 @@ const BrowserHandler = () => {
245254
try {
246255
const newRequestID = currentRequestID + 1;
247256
dispatch(resetMessages());
257+
dispatch(errorInConnection(false));
248258

249259
const request: WebsocketRequest = {
250260
bucket_name: bucketName,
@@ -266,7 +276,18 @@ const BrowserHandler = () => {
266276
const dupRequest = () => {
267277
initWSRequest(path, date);
268278
};
269-
initWSConnection(dupRequest, onMessageCallBack);
279+
280+
const fatalWSError = (message: string) => {
281+
dispatch(
282+
setErrorSnackMessage({
283+
errorMessage: message,
284+
detailedError: message,
285+
})
286+
);
287+
dispatch(errorInConnection(true));
288+
};
289+
290+
initWSConnection(dupRequest, onMessageCallBack, fatalWSError);
270291
}
271292
},
272293
[bucketName, rewindEnabled, showDeleted, dispatch, onMessageCallBack]

portal-ui/src/screens/Console/Buckets/ListBuckets/Objects/ListObjects/ListObjectsTable.tsx

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,13 @@ const ListObjectsTable = ({ internalPaths }: IListObjectTable) => {
117117
const selectedObjects = useSelector(
118118
(state: AppState) => state.objectBrowser.selectedObjects
119119
);
120+
const connectionError = useSelector(
121+
(state: AppState) => state.objectBrowser.connectionError
122+
);
120123
const anonymousMode = useSelector(
121124
(state: AppState) => state.system.anonymousMode
122125
);
126+
123127
const displayListObjects = hasPermission(bucketName, [
124128
IAM_SCOPES.S3_LIST_BUCKET,
125129
IAM_SCOPES.S3_ALL_LIST_BUCKET,
@@ -228,6 +232,21 @@ const ListObjectsTable = ({ internalPaths }: IListObjectTable) => {
228232
return elements;
229233
};
230234

235+
let errorMessage =
236+
!displayListObjects && !anonymousMode
237+
? permissionTooltipHelper(
238+
[IAM_SCOPES.S3_LIST_BUCKET, IAM_SCOPES.S3_ALL_LIST_BUCKET],
239+
"view Objects in this bucket"
240+
)
241+
: `This location is empty${
242+
!rewindEnabled ? ", please try uploading a new file" : ""
243+
}`;
244+
245+
if (connectionError) {
246+
errorMessage =
247+
"Objects List unavailable. Please review your WebSockets configuration and try again";
248+
}
249+
231250
return (
232251
<TableWrapper
233252
itemActions={tableActions}
@@ -241,16 +260,7 @@ const ListObjectsTable = ({ internalPaths }: IListObjectTable) => {
241260
} ${detailsOpen ? "actionsPanelOpen" : ""}`}
242261
selectedItems={selectedObjects}
243262
onSelect={!anonymousMode ? selectListObjects : undefined}
244-
customEmptyMessage={
245-
!displayListObjects && !anonymousMode
246-
? permissionTooltipHelper(
247-
[IAM_SCOPES.S3_LIST_BUCKET, IAM_SCOPES.S3_ALL_LIST_BUCKET],
248-
"view Objects in this bucket"
249-
)
250-
: `This location is empty${
251-
!rewindEnabled ? ", please try uploading a new file" : ""
252-
}`
253-
}
263+
customEmptyMessage={errorMessage}
254264
sortConfig={{
255265
currentSort: currentSortField,
256266
currentDirection: sortDirection,

portal-ui/src/screens/Console/ObjectBrowser/objectBrowserSlice.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const initialState: ObjectBrowserState = {
3636
objectDetailsOpen: false,
3737
loadingVersions: true,
3838
loadingObjectInfo: true,
39+
connectionError: false,
3940
rewind: {
4041
...defaultRewind,
4142
},
@@ -365,6 +366,14 @@ export const objectBrowserSlice = createSlice({
365366
setAnonymousAccessOpen: (state, action: PayloadAction<boolean>) => {
366367
state.anonymousAccessOpen = action.payload;
367368
},
369+
errorInConnection: (state, action: PayloadAction<boolean>) => {
370+
state.connectionError = action.payload;
371+
if (action.payload) {
372+
state.loadingObjects = false;
373+
state.loadingObjectInfo = false;
374+
state.objectDetailsOpen = false;
375+
}
376+
},
368377
},
369378
});
370379
export const {
@@ -412,6 +421,7 @@ export const {
412421
setSelectedBucket,
413422
setLongFileOpen,
414423
setAnonymousAccessOpen,
424+
errorInConnection,
415425
} = objectBrowserSlice.actions;
416426

417427
export default objectBrowserSlice.reducer;

portal-ui/src/screens/Console/ObjectBrowser/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export interface ObjectBrowserState {
9696
retentionConfig: IRetentionConfig | null;
9797
longFileOpen: boolean;
9898
anonymousAccessOpen: boolean;
99+
connectionError: boolean;
99100
}
100101

101102
export interface ObjectManager {

0 commit comments

Comments
 (0)