Bluebird: promisify xhr request I use bluebird promises. I want to promisify my requests from communication layer:

Utils.js

//Question: is there more beautiful way to do that?
promisifyXMLHttpRequest(xhr, timeout = 0, timeoutCallback = _.noop, responseHandler = response =&gt; JSON.parse(response).data) {
    const requestPromise = new Promise((resolve, reject) =&gt; {
        xhr.onload = () =&gt; {
            if (xhr.readyState === 4) {
                if (xhr.status === 200) {
                    resolve(responseHandler(xhr.responseText));
                } else {
                    reject(xhr.statusText);
                }
            }
        };
        xhr.onerror = function (e) {
            reject(xhr.statusText);
        };
    });

    if (timeout) {
        requestPromise.timeout(timeout)
            .catch(TimeoutError, error =&gt; {
                timeoutCallback(error);
            });
    }

    return requestPromise;
}


Communication

_sendRequest(body, sessionId, timeout, timeoutCallback, responseHandler) {
    const xhr = new XMLHttpRequest();
    xhr.open('POST', SOME_URL, true);
    if (sessionId) xhr.setRequestHeader('swarm-session', sessionId);
    const requestPromise = Utils.promisifyXMLHttpRequest(xhr, timeout, timeoutCallback, responseHandler);
    xhr.send(JSON.stringify(body));
    return requestPromise;
}
This seems quite fine to me.
One thing that pops to mind is that I lose the ability to see the status code of the error as you only reject with the message text. I would wrap that in an object where the statuscode is also exposed.