Skip to content

xhrInterceptor support async response #140

@yucopowo

Description

@yucopowo

XMLHttpRequestInterceptor

if (response instanceof Promise) {
    this.readyState = readyState;
    this.status = status;
    //TODO: should 'this.response' be the response string or the response json?
    response.then(function(data) {
        payload = data;
        if (data instanceof _Response.Response) {
            var responseHeaders = data.headers;

            payload = data.body;
            status = data.code;

            Object.assign(_this._responseHeaders, responseHeaders);
        }

        var responseString = JSON.stringify(payload);
        _this.responseText = _this.response = responseString;

        var requestDelay = helpers.getDelay();
        if (!requestDelay) {
            // for backwards compatibility if there is no requestDelay ot it 0 return callback without setTimeout
            successCallback.call(_this);
        } else {
            return setTimeout(function() {
                successCallback.call(_this);
            },
            requestDelay);
        }
    });

    return setTimeout(function() {},
    0);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions