Skip to content

Commit

Permalink
ZENKO-3056 Fix unexpected error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas2bert committed Dec 21, 2020
1 parent ef8fc1d commit acea850
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 38 deletions.
4 changes: 2 additions & 2 deletions src/js/S3Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default class S3Client {
Bucket,
Delimiter: '/',
Prefix,
MaxKeys: 1000,
MaxKeys: 100,
ContinuationToken,
}).promise();
}
Expand All @@ -90,7 +90,7 @@ export default class S3Client {
Bucket,
Prefix,
Delimiter: '/',
MaxKeys: 1000,
MaxKeys: 100,
KeyMarker,
VersionIdMarker,
}).promise();
Expand Down
4 changes: 2 additions & 2 deletions src/react/actions/__tests__/account.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('account actions', () => {
storeState: errorManagementState(),
expectedActions: [
createAccountNetworkAction,
dispatchAction.HANDLE_ERROR_SPEC_ACTION('The server is temporarily unavailable.'),
dispatchAction.HANDLE_ERROR_SPEC_ACTION('Management API Error Response'),
dispatchAction.NETWORK_END_ACTION,
],
},
Expand All @@ -74,7 +74,7 @@ describe('account actions', () => {
expectedActions: [
deleteAccountNetworkAction,
dispatchAction.CLOSE_ACCOUNT_DELETE_DIALOG_ACTION,
dispatchAction.HANDLE_ERROR_MODAL_ACTION('The server is temporarily unavailable.'),
dispatchAction.HANDLE_ERROR_MODAL_ACTION('Management API Error Response'),
dispatchAction.NETWORK_END_ACTION,
],
},
Expand Down
4 changes: 2 additions & 2 deletions src/react/actions/__tests__/location.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('location actions', () => {
storeState: errorManagementState(),
expectedActions: [
saveLocationNetworkStart,
dispatchAction.HANDLE_ERROR_SPEC_ACTION('The server is temporarily unavailable.'),
dispatchAction.HANDLE_ERROR_SPEC_ACTION('Management API Error Response'),
dispatchAction.NETWORK_END_ACTION,
],
},
Expand All @@ -81,7 +81,7 @@ describe('location actions', () => {
storeState: errorManagementState(),
expectedActions: [
deleteLocationNetworkAction,
dispatchAction.HANDLE_ERROR_MODAL_ACTION('The server is temporarily unavailable.'),
dispatchAction.HANDLE_ERROR_MODAL_ACTION('Management API Error Response'),
dispatchAction.NETWORK_END_ACTION,
dispatchAction.CLOSE_LOCATION_DELETE_DIALOG_ACTION,
],
Expand Down
4 changes: 2 additions & 2 deletions src/react/actions/__tests__/s3bucket.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('s3bucket actions', () => {
storeState: errorZenkoState(),
expectedActions: [
createBucketNetworkAction,
dispatchAction.HANDLE_ERROR_SPEC_ACTION('The server is temporarily unavailable.'),
dispatchAction.HANDLE_ERROR_SPEC_ACTION('S3 Client Api Error Response'),
dispatchAction.NETWORK_END_ACTION,
],
},
Expand Down Expand Up @@ -94,7 +94,7 @@ describe('s3bucket actions', () => {
storeState: errorZenkoState(),
expectedActions: [
deleteBucketNetworkAction,
dispatchAction.HANDLE_ERROR_MODAL_ACTION('The server is temporarily unavailable.'),
dispatchAction.HANDLE_ERROR_MODAL_ACTION('S3 Client Api Error Response'),
dispatchAction.NETWORK_END_ACTION,
dispatchAction.CLOSE_BUCKET_DELETE_DIALOG_ACTION,
],
Expand Down
28 changes: 14 additions & 14 deletions src/react/actions/__tests__/s3object.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ describe('s3object actions', () => {
storeState: errorZenkoState(),
expectedActions: [
createFolderNetworkAction,
dispatchAction.HANDLE_ERROR_SPEC_ACTION('The server is temporarily unavailable.'),
dispatchAction.HANDLE_ERROR_SPEC_ACTION('S3 Client Api Error Response'),
dispatchAction.NETWORK_END_ACTION,
dispatchAction.CLOSE_FOLDER_CREATE_MODAL_ACTION(),
],
Expand All @@ -145,7 +145,7 @@ describe('s3object actions', () => {
storeState: errorZenkoState(),
expectedActions: [
createFolderNetworkAction,
dispatchAction.HANDLE_ERROR_SPEC_ACTION('The server is temporarily unavailable.'),
dispatchAction.HANDLE_ERROR_SPEC_ACTION('S3 Client Api Error Response'),
dispatchAction.NETWORK_END_ACTION,
dispatchAction.CLOSE_FOLDER_CREATE_MODAL_ACTION(),
],
Expand Down Expand Up @@ -183,7 +183,7 @@ describe('s3object actions', () => {
expectedActions: [
dispatchAction.CLOSE_OBJECT_UPLOAD_MODAL_ACTION(),
uploadObjectsNetworkAction,
dispatchAction.HANDLE_ERROR_SPEC_ACTION('The server is temporarily unavailable.'),
dispatchAction.HANDLE_ERROR_SPEC_ACTION('S3 Client Api Error Response'),
dispatchAction.NETWORK_END_ACTION,
],
},
Expand All @@ -194,7 +194,7 @@ describe('s3object actions', () => {
expectedActions: [
dispatchAction.CLOSE_OBJECT_UPLOAD_MODAL_ACTION(),
uploadObjectsNetworkAction,
dispatchAction.HANDLE_ERROR_SPEC_ACTION('The server is temporarily unavailable.'),
dispatchAction.HANDLE_ERROR_SPEC_ACTION('S3 Client Api Error Response'),
dispatchAction.NETWORK_END_ACTION,
],
},
Expand Down Expand Up @@ -224,7 +224,7 @@ describe('s3object actions', () => {
storeState: errorZenkoState(),
expectedActions: [
listObjectsNetworkAction,
dispatchAction.HANDLE_ERROR_SPEC_ACTION('The server is temporarily unavailable.'),
dispatchAction.HANDLE_ERROR_SPEC_ACTION('S3 Client Api Error Response'),
dispatchAction.NETWORK_END_ACTION,
],
},
Expand All @@ -234,7 +234,7 @@ describe('s3object actions', () => {
storeState: errorZenkoState(),
expectedActions: [
listObjectsNetworkAction,
dispatchAction.HANDLE_ERROR_SPEC_ACTION('The server is temporarily unavailable.'),
dispatchAction.HANDLE_ERROR_SPEC_ACTION('S3 Client Api Error Response'),
dispatchAction.NETWORK_END_ACTION,
],
},
Expand Down Expand Up @@ -271,10 +271,10 @@ describe('s3object actions', () => {
expectedActions: [
dispatchAction.CLOSE_OBJECT_DELETE_MODAL_ACTION(),
deleteFilesNetworkAction,
dispatchAction.HANDLE_ERROR_MODAL_ACTION('The server is temporarily unavailable.'),
dispatchAction.HANDLE_ERROR_MODAL_ACTION('S3 Client Api Error Response'),
dispatchAction.NETWORK_END_ACTION,
listObjectsNetworkAction,
dispatchAction.HANDLE_ERROR_SPEC_ACTION('The server is temporarily unavailable.'),
dispatchAction.HANDLE_ERROR_SPEC_ACTION('S3 Client Api Error Response'),
dispatchAction.NETWORK_END_ACTION,
],
},
Expand All @@ -285,10 +285,10 @@ describe('s3object actions', () => {
expectedActions: [
dispatchAction.CLOSE_OBJECT_DELETE_MODAL_ACTION(),
deleteFilesNetworkAction,
dispatchAction.HANDLE_ERROR_MODAL_ACTION('The server is temporarily unavailable.'),
dispatchAction.HANDLE_ERROR_MODAL_ACTION('S3 Client Api Error Response'),
dispatchAction.NETWORK_END_ACTION,
listObjectsNetworkAction,
dispatchAction.HANDLE_ERROR_SPEC_ACTION('The server is temporarily unavailable.'),
dispatchAction.HANDLE_ERROR_SPEC_ACTION('S3 Client Api Error Response'),
dispatchAction.NETWORK_END_ACTION,
],
},
Expand All @@ -308,7 +308,7 @@ describe('s3object actions', () => {
storeState: errorZenkoState(),
expectedActions: [
gettingObjectMetadataNetworkAction,
dispatchAction.HANDLE_ERROR_SPEC_ACTION('The server is temporarily unavailable.'),
dispatchAction.HANDLE_ERROR_SPEC_ACTION('S3 Client Api Error Response'),
dispatchAction.NETWORK_END_ACTION,
],
},
Expand All @@ -318,7 +318,7 @@ describe('s3object actions', () => {
storeState: errorZenkoState(),
expectedActions: [
gettingObjectMetadataNetworkAction,
dispatchAction.HANDLE_ERROR_SPEC_ACTION('The server is temporarily unavailable.'),
dispatchAction.HANDLE_ERROR_SPEC_ACTION('S3 Client Api Error Response'),
dispatchAction.NETWORK_END_ACTION,
],
},
Expand All @@ -340,7 +340,7 @@ describe('s3object actions', () => {
storeState: errorZenkoState(),
expectedActions: [
gettingObjectMetadataNetworkAction,
dispatchAction.HANDLE_ERROR_MODAL_ACTION('The server is temporarily unavailable.'),
dispatchAction.HANDLE_ERROR_MODAL_ACTION('S3 Client Api Error Response'),
dispatchAction.NETWORK_END_ACTION,
],
},
Expand Down Expand Up @@ -374,7 +374,7 @@ describe('s3object actions', () => {
storeState: errorZenkoState(),
expectedActions: [
gettingObjectTagsNetworkAction,
dispatchAction.HANDLE_ERROR_MODAL_ACTION('The server is temporarily unavailable.'),
dispatchAction.HANDLE_ERROR_MODAL_ACTION('S3 Client Api Error Response'),
dispatchAction.NETWORK_END_ACTION,
],
},
Expand Down
27 changes: 20 additions & 7 deletions src/react/databrowser/objects/ObjectListTable.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow
import MemoRow, { createItemData } from './ObjectRow';
import React, { useMemo } from 'react';
import React, { useCallback, useMemo } from 'react';
import Table, * as T from '../../ui-elements/Table';
import { continueListObjects, toggleAllObjects, toggleObject } from '../../actions';
import { useDispatch, useSelector } from 'react-redux';
Expand All @@ -12,6 +12,7 @@ import InfiniteLoader from 'react-window-infinite-loader';
import { List } from 'immutable';
import type { Object } from '../../../types/s3';
import { formatBytes } from '../../utils';
import { push } from 'connected-react-router';
import styled from 'styled-components';

export const Icon = styled.i`
Expand All @@ -35,11 +36,20 @@ type Props = {
export default function ObjectListTable({ objects, bucketName, toggled, isVersioningType, prefixWithSlash }: Props){
const dispatch = useDispatch();
const nextMarker = useSelector((state: AppState) => state.s3.listObjectsResults.nextMarker);
const isItemLoaded = index => {
const shouldRefetch = nextMarker && index === objects.size - 1;
const loading = useSelector((state: AppState) => state.networkActivity.counter > 0);
const objectsLength = objects.size;
const isToggledFull = toggled.size > 0 && toggled.size === objectsLength;

const isItemLoaded = useCallback(index => {
const shouldRefetch = !loading && nextMarker && index === objectsLength - 1;
return !shouldRefetch;
};
const isToggledFull = toggled.size > 0 && toggled.size === objects.size;
}, [nextMarker, objectsLength, loading]);

const handleCellClicked = useCallback((bucketName, key) => (e) => {
e.stopPropagation();
dispatch(push(`/buckets/${bucketName}/objects/${key}`));
}, [dispatch]);

const columns = useMemo(() => [
{
id: 'checkbox',
Expand Down Expand Up @@ -71,7 +81,10 @@ export default function ObjectListTable({ objects, bucketName, toggled, isVersio
accessor: 'name',
Cell({ row: { original } }: CellProps) {
if (original.isFolder) {
return <span> <Icon className='far fa-folder'></Icon><T.CellLink to={{ pathname: `/buckets/${bucketName}/objects/${original.key}` }}>{original.name}</T.CellLink></span>;
return <span>
<Icon className='far fa-folder'></Icon>
<T.CellClick onClick={handleCellClicked(bucketName, original.key)}>{original.name}</T.CellClick>
</span>;
}
if (original.isDeleteMarker) {
return <span> <Icon isMargin={!original.isLatest} className='fas fa-ban'></Icon>{original.name}</span>;
Expand Down Expand Up @@ -101,7 +114,7 @@ export default function ObjectListTable({ objects, bucketName, toggled, isVersio
accessor: row => row.size ? formatBytes(row.size) : '',
width: 15,
},
], [bucketName, dispatch, isToggledFull, isVersioningType]);
], [bucketName, dispatch, handleCellClicked, isToggledFull, isVersioningType]);

const hiddenColumns = isVersioningType ? [] : ['versionId'];

Expand Down
6 changes: 5 additions & 1 deletion src/react/databrowser/objects/Objects.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ export default function Objects(){
// NOTE: If only one unique object (not folder) is selected, we show its metadata.
// Otherwise, we clear object metadata.
useEffect(() => {
// wait for objects to be listed.
if (!loaded) {
return;
}
const firstToggledItem = toggled.first();
if (toggled.size === 1 && !firstToggledItem.isFolder && !firstToggledItem.isDeleteMarker) {
dispatch(getObjectMetadata(bucketNameParam, firstToggledItem.key, firstToggledItem.versionId));
} else {
dispatch(resetObjectMetadata());
}
}, [dispatch, bucketNameParam, toggled]);
}, [dispatch, bucketNameParam, toggled, loaded]);

if (!loaded || !bucketInfo) {
return <ObjectHead/>;
Expand Down
42 changes: 42 additions & 0 deletions src/react/utils/__tests__/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,41 +38,83 @@ describe('functions utils', () => {
},
expectedErrorMessage: errorMessages[1],
},
{
it: `should return the error message: "${errorMessages[1]}" if S3 api status code is 401`,
error: {
statusCode: 401,
},
expectedErrorMessage: errorMessages[1],
},
{
it: `should return the error message: "${errorMessages[2]}" if status code is 403`,
error: {
status: 403,
},
expectedErrorMessage: errorMessages[2],
},
{
it: `should return the error message: "${errorMessages[2]}" if S3 api status code is 403`,
error: {
statusCode: 403,
},
expectedErrorMessage: errorMessages[2],
},
{
it: `should return the error message: "${errorMessages[3]}" if status code is 404`,
error: {
status: 404,
},
expectedErrorMessage: errorMessages[3],
},
{
it: `should return the error message: "${errorMessages[3]}" if S3 api status code is 404`,
error: {
statusCode: 404,
},
expectedErrorMessage: errorMessages[3],
},
{
it: `should return the error message: "${errorMessages[4]}" if status code is 409`,
error: {
status: 409,
},
expectedErrorMessage: errorMessages[4],
},
{
it: `should return the error message: "${errorMessages[4]}" if S3 api status code is 409`,
error: {
statusCode: 409,
},
expectedErrorMessage: errorMessages[4],
},
{
it: `should return the error message: "${errorMessages[5]}" if status code is 500`,
error: {
status: 500,
},
expectedErrorMessage: errorMessages[5],
},
{
it: `should return the error message: "${errorMessages[5]}" if S3 api status code is 500`,
error: {
statusCode: 500,
},
expectedErrorMessage: errorMessages[5],
},
{
it: `should return the error message: "${errorMessages[5]}" if status code is 503`,
error: {
status: 503,
},
expectedErrorMessage: errorMessages[5],
},
{
it: `should return the error message: "${errorMessages[5]}" if S3 api status code is 503`,
error: {
statusCode: 503,
},
expectedErrorMessage: errorMessages[5],
},
{
it: 'should return the error message contains in error.message if exists',
error: {
Expand Down
19 changes: 11 additions & 8 deletions src/react/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,23 @@ export function errorParser(error) {
if (error.response && error.response.body && error.response.body.message) {
message = error.response.body.message;
//! $FlowFixMe
} else if (error.status === 401) {
} else if (error.message) {
message = error.message;
} else if (error.status === 401 || error.statusCode === 401) {
message = 'The request is missing valid authentication credentials.';
} else if (error.status === 403) {
} else if (error.status === 403 || error.statusCode === 403) {
message = 'Access to the requested item was denied.';
} else if (error.status === 404) {
} else if (error.status === 404 || error.statusCode === 404) {
message = 'The requested item does not exist.';
} else if (error.status === 409) {
} else if (error.status === 409 || error.statusCode === 409) {
message = 'An item with the same identifier already exists.';
} else if (error.status === 500 || error.status === 503) {
} else if (error.status === 500 || error.status === 503
|| error.statusCode === 500 || error.statusCode === 503) {
message = 'The server is temporarily unavailable.';
} else if (error.message) {
message = error.message;
} else if (error.status || error.statusCode) {
message = `Failed with error status: ${String(error.status || error.statusCode)}`;
} else {
message = `Failed with error status: ${String(error.status)}`;
message = 'Request failed';
}
return { message };
}
Expand Down

0 comments on commit acea850

Please sign in to comment.