Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xhrInterceptor support async response #140

Open
yucopowo opened this issue Mar 9, 2017 · 1 comment
Open

xhrInterceptor support async response #140

yucopowo opened this issue Mar 9, 2017 · 1 comment

Comments

@yucopowo
Copy link

yucopowo commented Mar 9, 2017

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);
}
@yucopowo
Copy link
Author

yucopowo commented Mar 9, 2017

router.get('/async', function (request) {
    return new Promise(function (resolve, reject) {
        resolve({
            body:{
                a:1
            }
        });
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant