<commit_before>/**
 * Login server abstraction layer
 * Pokemon Showdown - http://pokemonshowdown.com/
 *
 * This file handles communicating with the login server.
 *
 * @license MIT license
 */

'use strict';

const LOGIN_SERVER_TIMEOUT = 30000;
const LOGIN_SERVER_BATCH_TIME = 1000;

const http = require("http");
const url = require('url');

const FS = require('./fs');

let TimeoutError = function (message) {
	Error.captureStackTrace(this, TimeoutError);
	this.name = "TimeoutError";
	this.message = message || "";
};
TimeoutError.prototype = Object.create(Error.prototype);
TimeoutError.prototype.constructor = TimeoutError;
TimeoutError.prototype.toString = function () {
	if (!this.message) return this.name;
	return this.name + ": " + this.message;
};

function parseJSON(json) {
	if (json[0] === ']') json = json.substr(1);
	let data = {error: null};
	try {
		data.json = JSON.parse(json);
	} catch (err) {
		data.error = err;
	}
	return data;
}

class LoginServerInstance {
	constructor() {
		this.uri = Config.loginserver;
		this.requestQueue = [];

		this.requestTimer = null;
		this.requestTimeoutTimer = null;
		this.requestLog = '';
		this.lastRequest = 0;
		this.openRequests = 0;
	}

	instantRequest(action, data, callback) {
		if (typeof data === 'function') {
			callback = data;
			data = null;
		}
		if (this.openRequests > 5) {
			setImmediate(callback, null, null, new RangeError("Request overflow"));
			return;
		}<commit_msg>Login Server: make TimeoutError a subclass of Error (#3779)<commit_after>/**
 * Login server abstraction layer
 * Pokemon Showdown - http://pokemonshowdown.com/
 *
 * This file handles communicating with the login server.
 *
 * @license MIT license
 */

'use strict';

const LOGIN_SERVER_TIMEOUT = 30000;
const LOGIN_SERVER_BATCH_TIME = 1000;

const http = require("http");
const url = require('url');

const FS = require('./fs');

/**
 * A custom error type used when requests to the login server take too long.
 */
class TimeoutError extends Error {}
TimeoutError.prototype.name = TimeoutError.name;

function parseJSON(json) {
	if (json.startsWith(']')) json = json.substr(1);
	let data = {error: null};
	try {
		data.json = JSON.parse(json);
	} catch (err) {
		data.error = err;
	}
	return data;
}

class LoginServerInstance {
	constructor() {
		this.uri = Config.loginserver;
		this.requestQueue = [];

		this.requestTimer = null;
		this.requestTimeoutTimer = null;
		this.requestLog = '';
		this.lastRequest = 0;
		this.openRequests = 0;
	}

	instantRequest(action, data, callback) {
		if (typeof data === 'function') {
			callback = data;
			data = null;
		}
		if (this.openRequests > 5) {
			setImmediate(callback, null, null, new RangeError("Request overflow"));
			return;
		}
{'fraction_non_alphanumeric': 0.13951789627465302, 'fraction_numerical': 0.011322132943754566, 'mean_word_length': 4.0349264705882355, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 5, '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': '5781344', 'n_tokens_mistral': 952, 'n_tokens_neox': 876, 'n_words': 233}