File tree Expand file tree Collapse file tree 3 files changed +34
-4
lines changed
Expand file tree Collapse file tree 3 files changed +34
-4
lines changed Original file line number Diff line number Diff line change @@ -181,10 +181,7 @@ export class Dropzone extends Component {
181181 if ( this . readyState === XMLHttpRequest . DONE && this . status === 200 ) {
182182 upload . markSuccess ( component . successMessage ) ;
183183 } else if ( this . readyState === XMLHttpRequest . DONE && this . status >= 400 ) {
184- const content = this . responseText ;
185- const data = content . startsWith ( '{' ) ? JSON . parse ( content ) : { message : content } ;
186- const message = data ?. message || data ?. error || content ;
187- upload . markError ( message ) ;
184+ upload . markError ( window . $http . formatErrorResponseText ( this . responseText ) ) ;
188185 }
189186 } ,
190187 } ) ;
Original file line number Diff line number Diff line change @@ -207,3 +207,32 @@ async function performDelete(url, data = null) {
207207}
208208
209209export { performDelete as delete } ;
210+
211+ /**
212+ * Parse the response text for an error response to a user
213+ * presentable string. Handles a range of errors responses including
214+ * validation responses & server response text.
215+ * @param {String } text
216+ * @returns {String }
217+ */
218+ export function formatErrorResponseText ( text ) {
219+ const data = text . startsWith ( '{' ) ? JSON . parse ( text ) : { message : text } ;
220+ if ( ! data ) {
221+ return text ;
222+ }
223+
224+ if ( data . message || data . error ) {
225+ return data . message || data . error ;
226+ }
227+
228+ const values = Object . values ( data ) ;
229+ const isValidation = values . every ( val => {
230+ return Array . isArray ( val ) || val . every ( x => typeof x === 'string' ) ;
231+ } ) ;
232+
233+ if ( isValidation ) {
234+ return values . flat ( ) . join ( ' ' ) ;
235+ }
236+
237+ return text ;
238+ }
Original file line number Diff line number Diff line change @@ -321,6 +321,10 @@ body.flexbox-support #entity-selector-wrap .popup-body .form-group {
321321 background-color : var (--color-primary );
322322 transition : width ease-in-out 240ms ;
323323}
324+ .dropzone-file-item-label {
325+ line-height : 1.2 ;
326+ margin-bottom : .2rem ;
327+ }
324328.dropzone-file-item-label ,
325329.dropzone-file-item-status {
326330 align-items : center ;
You can’t perform that action at this time.
0 commit comments