<commit_before>/**
 * Created by lakhe on 6/5/16.
 */

(function (errorHelper) {

    'use strict';

    errorHelper.formatErrorObj = function (err) {
        var formatError = err.toString();
        var obj = JSON.parse(
            JSON.stringify(
                formatError
                    .substring(
                        formatError.indexOf("{")
                    )
            )
        );
        return JSON.parse(obj);
    };
    
    errorHelper.outputJSONErrorMessage = function (err, next) {
        try {
            var obj = errorHelper.formatErrorObj(err);
            return {
                statusCode:obj.statusCode,
                message: obj.message
            };
        }
        catch(err) {
            return  next(err);
        }
    };

    errorHelper.getErrorObj = function (err, next) {
        try {

            var errorObj = {
                errorMessage : '',
                errorStack : '',
                errorType : ''
            };
            errorObj.errorMessage = err.message;
            errorObj.errorStack = err.stack;
            errorObj.errorType = err.name;
            return errorObj;
        }<commit_msg>error log to the database issue fixed in case of string error response<commit_after>/**
 * Created by lakhe on 6/5/16.
 */

(function (errorHelper) {

    'use strict';

    errorHelper.formatErrorObj = function (err) {
        var formatError = err.toString();
        var obj = JSON.parse(
            JSON.stringify(
                formatError
                    .substring(
                        formatError.indexOf("{")
                    )
            )
        );
        return JSON.parse(obj);
    };
    
    errorHelper.outputJSONErrorMessage = function (err, next) {
        try {
            var obj = errorHelper.formatErrorObj(err);
            return {
                statusCode:obj.statusCode,
                message: obj.message
            };
        }
        catch(err) {
            return  next(err);
        }
    };

    errorHelper.getErrorObj = function (err, next) {
        try {

            var errorObj = {
                errorMessage : '',
                errorStack : '',
                errorType : ''
            };
            if(typeof err === 'string'){
                errorObj.errorMessage = err;
                errorObj.errorStack = err;
                errorObj.errorType = '';
            }else{
                errorObj.errorMessage = err.message;
                errorObj.errorStack = err.stack;
                errorObj.errorType = err.name;
            }
            return errorObj;
        }
{'fraction_non_alphanumeric': 0.09817351598173515, 'fraction_numerical': 0.0030441400304414, 'mean_word_length': 1.1853699085619285, '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': '2855670', 'n_tokens_mistral': 689, 'n_tokens_neox': 651, 'n_words': 137}