diff --git a/client/src/components/UploadField/UploadField.js b/client/src/components/UploadField/UploadField.js index c22f6ae3a..dcc69ac3d 100644 --- a/client/src/components/UploadField/UploadField.js +++ b/client/src/components/UploadField/UploadField.js @@ -234,7 +234,7 @@ class UploadField extends Component { handleFailedUpload(file, response) { const statusCodeMessage = file.xhr && file.xhr.status - ? getStatusCodeMessage(file.xhr.status) + ? getStatusCodeMessage(file.xhr.status, file.xhr) : ''; this.props.actions.uploadField.failUpload( this.props.id, diff --git a/client/src/containers/Gallery/Gallery.js b/client/src/containers/Gallery/Gallery.js index 2331d74ef..8d50bc75c 100644 --- a/client/src/containers/Gallery/Gallery.js +++ b/client/src/containers/Gallery/Gallery.js @@ -318,11 +318,11 @@ class Gallery extends Component { } } - /** - * Handler for when the user changes the sort order - * - * @param {string} value - */ + /** + * Handler for when the user changes the sort order + * + * @param {string} value + */ handleSort(value) { this.props.actions.queuedFiles.purgeUploadQueue(); this.props.onSort(value); @@ -436,7 +436,7 @@ class Gallery extends Component { handleFailedUpload(fileXhr, response) { const statusCodeMessage = fileXhr.xhr && fileXhr.xhr.status - ? getStatusCodeMessage(fileXhr.xhr.status) + ? getStatusCodeMessage(fileXhr.xhr.status, fileXhr.xhr) : ''; this.props.actions.queuedFiles.failUpload(fileXhr._queuedId, response, statusCodeMessage); } @@ -868,10 +868,10 @@ class Gallery extends Component {

- { i18n._t('AssetAdmin.DROPZONE_RESPONSE_ERROR', 'Server responded with an error.') } + {i18n._t('AssetAdmin.DROPZONE_RESPONSE_ERROR', 'Server responded with an error.')}

- { errorMessage &&

{ errorMessage }

} - { hasGraphQLErrors && graphQLErrors.map((error, index) => ( + {errorMessage &&

{errorMessage}

} + {hasGraphQLErrors && graphQLErrors.map((error, index) => ( // eslint-disable-next-line react/no-array-index-key

{error}

))} @@ -897,10 +897,10 @@ class Gallery extends Component { const messages = (
- { errorMessage && + {errorMessage && } - { noticeMessage && + {noticeMessage && }
@@ -972,7 +972,7 @@ class Gallery extends Component { - { this.props.loading && } + {this.props.loading && } { const status413Message = getStatusCodeMessage(413); expect(status413Message.length > 0 && status413Message !== defaultMessage).toBe(true); }); + it('To display validation messages for a 403 status code', () => { + const mockResponse = { + responseType: '', + response: 'Validation Message', + }; + const status403Message = getStatusCodeMessage(403, mockResponse); + expect(status403Message.length > 0 && status403Message !== defaultMessage).toBe(true); + expect(status403Message).toBe('Validation Message'); + + const mockNonTextResponse = { + responseType: 'arraybuffer', + response: new ArrayBuffer(), + }; + const status403NonTextMessage = getStatusCodeMessage(403, mockNonTextResponse); + expect(status403NonTextMessage.length > 0 && status403NonTextMessage === defaultMessage) + .toBe(true); + }); });