<commit_before>
// Constructs a new httpClient
// 
// o may be a string (URL endpoint to access) or a function
// 
// If o is a function:
//
//  * When a request is made, your function will get two args: request, callback
//  * request is an object that represents JSON-RPC request
//  * your code should call: Barrister.JSON_stringify(req) to serialize it to JSON. This stringify
//    function properly escapes non-ASCII characters to ensure uniform behavior across servers.
//  * Make a POST request to the endpoint as desired, make sure to set Content-Type to
//    "application/json"
//  * Invoke the callback with a JSON-RPC response.  Use the `Barrister.parseResponse` helper
//    function to simplify this.  Pass it the original req you were given, 
//    an error string (if the request failed, or null if succeeded), and the raw response body.
//
// opts is an optional object that is passed to the Client -- 
// see the Client constructor for details
//
var httpClient = function(o, opts) {
    var transport = o;

    // Assume that o is an URL endpoint
    if (typeof o === "string") {
        transport = function(req, callback) {
            var settings = {
                type: "POST",
                contentType: "application/json",
                data: JSON_stringify(req),
                converters: { 
                    "text json" : function(data) {
                        // Parse JSON ourselves to ensure that parse errors
                        // are trapped and correct error code returned
                        return parseResponse(req, null, data);
                    }
                },
                error: function(jqXHR, textStatus, errorThrown) {
                    callback(parseResponse(req, textStatus+" "+errorThrown, null));
                },
                success: function(data, textStatus, jqXHR) {
                    callback(parseResponse(req, null, data));
                }
            };
            jQuery.ajax(o, settings);
        };
    }

    return new Client(transport, opts);
};

// Export blessed functions to the Barrister namespace
Barrister.httpClient = httpClient;
Barrister.parseResponse = parseResponse;
Barrister.Client = Client;
Barrister.Contract = Contract;
Barrister.JSON_stringify = JSON_stringify;

}());<commit_msg>httpClient: translate xhr.status===0 to json-rpc error -32002 so clients know HTTP request was aborted<commit_after>
// Constructs a new httpClient
// 
// o may be a string (URL endpoint to access) or a function
// 
// If o is a function:
//
//  * When a request is made, your function will get two args: request, callback
//  * request is an object that represents JSON-RPC request
//  * your code should call: Barrister.JSON_stringify(req) to serialize it to JSON. This stringify
//    function properly escapes non-ASCII characters to ensure uniform behavior across servers.
//  * Make a POST request to the endpoint as desired, make sure to set Content-Type to
//    "application/json"
//  * Invoke the callback with a JSON-RPC response.  Use the `Barrister.parseResponse` helper
//    function to simplify this.  Pass it the original req you were given, 
//    an error string (if the request failed, or null if succeeded), and the raw response body.
//
// opts is an optional object that is passed to the Client -- 
// see the Client constructor for details
//
var httpClient = function(o, opts) {
    var transport = o;

    // Assume that o is an URL endpoint
    if (typeof o === "string") {
        transport = function(req, callback) {
            var settings = {
                type: "POST",
                contentType: "application/json",
                data: JSON_stringify(req),
                converters: { 
                    "text json" : function(data) {
                        // Parse JSON ourselves to ensure that parse errors
                        // are trapped and correct error code returned
                        return parseResponse(req, null, data);
                    }
                },
                error: function(jqXHR, textStatus, errorThrown) {
                    var resp;
                    if (jqXHR && jqXHR.status === 0) {
                        resp = errResp(req.id, -32002, "HTTP request aborted", jqXHR);
                    }
                    else {
                        resp = parseResponse(req, textStatus+" "+errorThrown, null);
                    }
                    callback(resp);
                },
                success: function(data, textStatus, jqXHR) {
                    callback(parseResponse(req, null, data));
                }
            };
            jQuery.ajax(o, settings);
        };
    }

    return new Client(transport, opts);
};

// Export blessed functions to the Barrister namespace
Barrister.httpClient = httpClient;
Barrister.parseResponse = parseResponse;
Barrister.Client = Client;
Barrister.Contract = Contract;
Barrister.JSON_stringify = JSON_stringify;

}());
{'fraction_non_alphanumeric': 0.0897770636674031, 'fraction_numerical': 0.002410122514561157, 'mean_word_length': 1.9537366548042705, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5769439', 'n_tokens_mistral': 1289, 'n_tokens_neox': 1226, 'n_words': 485}