Skip to content

Commit

Permalink
feat: responseStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
kukhariev committed Mar 1, 2019
1 parent 71fcab9 commit d9a1bb8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/uploadx/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface UploadState {
percentage: number;
remaining: number;
response: any;
responseStatus: number;
size: number;
speed: number;
status: UploadStatus;
Expand Down
5 changes: 5 additions & 0 deletions src/uploadx/src/uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class Uploader implements UploaderOptions {
readonly uploadId: string;
remaining: number;
response: any;
responseStatus: number;
speed: number;
URI: string;

Expand Down Expand Up @@ -72,6 +73,7 @@ export class Uploader implements UploaderOptions {
percentage: this.progress,
remaining: this.remaining,
response: this.response,
responseStatus: this.responseStatus,
size: this.size,
speed: this.speed,
status: this._status,
Expand Down Expand Up @@ -113,6 +115,7 @@ export class Uploader implements UploaderOptions {
xhr.setRequestHeader('X-Upload-Content-Length', this.size.toString());
xhr.setRequestHeader('X-Upload-Content-Type', this.mimeType);
xhr.onload = () => {
this.responseStatus = xhr.status;
this.response = parseJson(xhr);
if (xhr.status < 400 && xhr.status > 199) {
const location = getKeyFromResponse(xhr, 'location');
Expand Down Expand Up @@ -187,6 +190,7 @@ export class Uploader implements UploaderOptions {

private setupEvents(xhr: XMLHttpRequest) {
const onError = async () => {
this.responseStatus = xhr.status;
// 5xx errors or network failures
if (xhr.status > 499 || !xhr.status) {
XHRFactory.release(xhr);
Expand All @@ -205,6 +209,7 @@ export class Uploader implements UploaderOptions {
}
};
const onSuccess = () => {
this.responseStatus = xhr.status;
if (xhr.status === 200 || xhr.status === 201) {
this.progress = 100;
this.response = parseJson(xhr);
Expand Down

0 comments on commit d9a1bb8

Please sign in to comment.