Merge pull request #5050 from betagouv/improve-file-upload-errors

Javascript : amélioration du formattage des erreurs d'upload
This commit is contained in:
Pierre de La Morinerie 2020-04-16 17:15:56 +02:00 committed by GitHub
commit 99c8300c10
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 6 deletions

View file

@ -30,7 +30,7 @@ export default class FileUploadError extends Error {
See FAILURE_* constants for values. See FAILURE_* constants for values.
*/ */
get failureReason() { get failureReason() {
let isNetworkError = this.code != ERROR_CODE_READ; let isNetworkError = this.code && this.code != ERROR_CODE_READ;
if (isNetworkError && this.status != 0) { if (isNetworkError && this.status != 0) {
return FAILURE_SERVER; return FAILURE_SERVER;
@ -51,8 +51,8 @@ export default class FileUploadError extends Error {
// (so that Sentry knows they are different kind of errors, from // (so that Sentry knows they are different kind of errors, from
// the line they were created.) // the line they were created.)
export function errorFromDirectUploadMessage(message) { export function errorFromDirectUploadMessage(message) {
let matches = message.match(/ Status: [0-9]{1,3}/); let matches = message.match(/ Status: ([0-9]{1,3})/);
let status = (matches && parseInt(matches[0], 10)) || undefined; let status = matches ? parseInt(matches[1], 10) : undefined;
// prettier-ignore // prettier-ignore
if (message.includes('Error reading')) { if (message.includes('Error reading')) {

View file

@ -30,11 +30,12 @@ export default class Uploader {
if (this.autoAttachUrl) { if (this.autoAttachUrl) {
await this._attach(blobSignedId); await this._attach(blobSignedId);
// On response, the attachment HTML fragment will replace the progress bar.
} else {
this.progressBar.end();
this.progressBar.destroy();
} }
this.progressBar.end();
this.progressBar.destroy();
return blobSignedId; return blobSignedId;
} catch (error) { } catch (error) {
this.progressBar.error(error.message); this.progressBar.error(error.message);