Skip to content

Commit

Permalink
fix(upload-core): pass xhr error message to UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Christie Baker authored and Christie Baker committed Apr 23, 2018
1 parent 3490616 commit 6676650
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions packages/upload-core/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Upload {
this.bytesSent = 0;
this.bytesScanned = 0;
this.errorMessage = null;
this.errorCode = null;
this.status = 'pending';
this.timeoutID = undefined;
this.error = null;
Expand Down Expand Up @@ -316,8 +317,27 @@ class Upload {
setError(status, message, err) {
if (!this.hasError()) {
this.status = status;
this.errorMessage = message || 'An error occurred';
this.onError.forEach(cb => cb(err || new Error(message)));
this.parseErrorMessage(message, err);
this.onError.forEach(cb => cb(err || new Error(this.errorMessage)));
}
}

parseErrorMessage(message, err) {
if (err) {
const originalErrorMessage = err.message;
let temp = originalErrorMessage.match(/response\Wcode:\W([0-9]*)/);
if (temp && temp.length === 2) {
[, this.errorCode] = temp;
}
temp = originalErrorMessage.match(/response\Wtext:\W(.*)\)/);
if (temp && temp.length === 2) {
[, this.errorMessage] = temp;
}
if (!this.errorMessage && this.errorMessage !== '') {
this.errorMessage = message;
}
} else {
this.errorMessage = message;
}
}

Expand Down

0 comments on commit 6676650

Please sign in to comment.