javascript: don't allow to retry on direct upload 422
When the authenticity token is invalid, the creation of the blob before the direct upload returns a 422. In that case, the token will never become valid again, and it is useless to try again. Don’t show the "Retry" button in this case. NB: of course the real fix is to understand why the authenticity token is so often invalid – but this will be for later.
This commit is contained in:
parent
38b0bd645c
commit
444732b117
1 changed files with 13 additions and 2 deletions
|
@ -93,7 +93,18 @@ export default class AutoUploadController {
|
|||
this.input.disabled = false;
|
||||
}
|
||||
|
||||
_isError422(error) {
|
||||
// Ajax errors have an xhr attribute
|
||||
if (error && error.xhr && error.xhr.status == 422) return true;
|
||||
// Rails DirectUpload errors are returned as a String, e.g. 'Error creating Blob for "Demain.txt". Status: 422'
|
||||
if (error && error.toString().includes('422')) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
_messageFromError(error) {
|
||||
let allowRetry = !this._isError422(error);
|
||||
|
||||
if (
|
||||
error.xhr &&
|
||||
error.xhr.status == 422 &&
|
||||
|
@ -104,13 +115,13 @@ export default class AutoUploadController {
|
|||
return {
|
||||
title: error.response.errors[0],
|
||||
description: '',
|
||||
retry: false
|
||||
retry: allowRetry
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
title: 'Une erreur s’est produite pendant l’envoi du fichier.',
|
||||
description: error.message || error.toString(),
|
||||
retry: true
|
||||
retry: allowRetry
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue