<commit_before>const Database = require('../../db');
const authMiddleware = require('../../authMiddleware');

const config = require('../../config')();

const cashflow = require('./cashflow');
const analysis = require('./analysis');
const analysisDeep = require('./analysis/deep');

const income = require('./income');
const bills = require('./bills');
const funds = require('./funds');
const food = require('./food');
const general = require('./general');
const social = require('./social');
const holiday = require('./holiday');

const listDataProcessor = { income, bills, funds, food, general, social, holiday };

const stocks = require('./stocks');

class ResponseMultiple {
    // replicate the response object so that we can return multiple
    // api endpoint responses
    constructor() {
        this.statusCode = 200;
        this.result = null;
        this.ended = false;
    }
    json(object) {
        this.result = object;

        return this;
    }
    end(string) {
        if (string) {
            this.result = string;
        }

        this.ended = true;

        return this;
    }
    status(statusCode) {
        this.statusCode = statusCode;

        return this;
    }
}

function getOverallStatusCode(results) {
    return results.reduce((status, taskRes) => {
        // use the following status codes, in order of precedence
        if (taskRes.statusCode >= 500) {
            // server error
            if (status >= 500 && status !== taskRes.statusCode) {
                return 500;
            }

            return taskRes.statusCode;
        }
        if (status < 500 && taskRes.statusCode >= 400) {
            // client error
            if (status >= 400 && status !== taskRes.statusCode) {
                return 400;
            }

            return taskRes.statusCode;
        }
        if (status < 400 && taskRes.statusCode < 300 && taskRes.statusCode >= 200) {
            // success code
            if (status >= 200 && status !== taskRes.statusCode) {
                return 200;
            }

            return taskRes.statusCode;
        }

        return status;
    }, 0);
}

function validateTaskList(list) {
    if (!Array.isArray(list)) {
        return false;
    }<commit_msg>Handle error in multiple-status code<commit_after>const Database = require('../../db');
const authMiddleware = require('../../authMiddleware');

const config = require('../../config')();

const cashflow = require('./cashflow');
const analysis = require('./analysis');
const analysisDeep = require('./analysis/deep');

const income = require('./income');
const bills = require('./bills');
const funds = require('./funds');
const food = require('./food');
const general = require('./general');
const social = require('./social');
const holiday = require('./holiday');

const listDataProcessor = { income, bills, funds, food, general, social, holiday };

const stocks = require('./stocks');

class ResponseMultiple {
    // replicate the response object so that we can return multiple
    // api endpoint responses
    constructor() {
        this.statusCode = 200;
        this.result = null;
        this.ended = false;
    }
    json(object) {
        this.result = object;

        return this;
    }
    end(string) {
        if (string) {
            this.result = string;
        }

        this.ended = true;

        return this;
    }
    status(statusCode) {
        this.statusCode = statusCode;

        return this;
    }
}

function getOverallStatusCode(results) {
    const statusCode = results.reduce((status, taskRes) => {
        // use the following status codes, in order of precedence
        if (taskRes.statusCode >= 500) {
            // server error
            if (status >= 500 && status !== taskRes.statusCode) {
                return 500;
            }

            return taskRes.statusCode;
        }
        if (status < 500 && taskRes.statusCode >= 400) {
            // client error
            if (status >= 400 && status !== taskRes.statusCode) {
                return 400;
            }

            return taskRes.statusCode;
        }
        if (status < 400 && taskRes.statusCode < 300 && taskRes.statusCode >= 200) {
            // success code
            if (status >= 200 && status !== taskRes.statusCode) {
                return 200;
            }

            return taskRes.statusCode;
        }

        return status;
    }, 0);

    if (!statusCode) {
        return 500;
    }

    return statusCode;
}

function validateTaskList(list) {
    if (!Array.isArray(list)) {
        return false;
    }
{'fraction_non_alphanumeric': 0.13439337834894358, 'fraction_numerical': 0.018078849923763886, 'mean_word_length': 1.9856957087126137, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, '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': '2733303', 'n_tokens_mistral': 1287, 'n_tokens_neox': 1176, 'n_words': 337}