<commit_before>'use strict';
/*
 * Handle Kancolle's request to external resources
 */
var express = require('express');
var router = express.Router();
var path = require('path');

var settings = require('nconf');
var kancolleExternal = require('../model/kancolleExternal');
var agent = require('../model/agent');
const appLog = require('winston').loggers.get('app');
const expressLog = require('winston').loggers.get('express');

router.get('/resources/image/world/:worldImg.png', function(req, res, next) {
   expressLog.info('GET: ' + req.originalUrl);
   var host = new RegExp(req.headers.host, 'gi');
   var worldImageUrl = req.url.replace(host, settings.get('MY_WORLD_SERVER'))
   .replace(/\./g, '_')
   .replace('_png', '.png');

   agent.load(res, worldImageUrl, handleFileNotFound(worldImageUrl, res, next));
})

var urlEndWithFileType = /^.*\.(swf|mp3|png)$/i;
router.get(urlEndWithFileType, function(req, res, next) {
   expressLog.info('GET: ' + req.originalUrl);
   var path2file = path.join(req.baseUrl, req.path);

   agent.load(res, path2file, handleFileNotFound(req.originalUrl, res, next));
});

function handleFileNotFound(urlDownload, res, next) {
   return function(error) {
      var fileNotFound = error && error.status === 404;
      if(fileNotFound) {
         var resource = kancolleExternal.kcsResource(urlDownload);
         appLog.info('File not found or not cached');
         appLog.info('Get resource from: ' + resource);
         return agent.download(res, resource, function(response) {
            appLog.info('Download Completed');
            appLog.info('Source URL: ' + resource);
            appLog.debug('Return status code: ' + response.statusCode);
            appLog.debug('Response header: ' + response.headers);
         });
      }
      else {
         appLog.error(error);
         return next(error);
      }
   }
}

module.exports = exports = router;<commit_msg>[fix] application log error as undefined when there is no error<commit_after>'use strict';
/*
 * Handle Kancolle's request to external resources
 */
var express = require('express');
var router = express.Router();
var path = require('path');

var settings = require('nconf');
var kancolleExternal = require('../model/kancolleExternal');
var agent = require('../model/agent');
const appLog = require('winston').loggers.get('app');
const expressLog = require('winston').loggers.get('express');

router.get('/resources/image/world/:worldImg.png', function(req, res, next) {
   expressLog.info('GET: ' + req.originalUrl);
   var host = new RegExp(req.headers.host, 'gi');
   var worldImageUrl = req.url.replace(host, settings.get('MY_WORLD_SERVER'))
   .replace(/\./g, '_')
   .replace('_png', '.png');

   agent.load(res, worldImageUrl, handleFileNotFound(worldImageUrl, res, next));
})

var urlEndWithFileType = /^.*\.(swf|mp3|png)$/i;
router.get(urlEndWithFileType, function(req, res, next) {
   expressLog.info('GET: ' + req.originalUrl);
   var path2file = path.join(req.baseUrl, req.path);

   agent.load(res, path2file, handleFileNotFound(req.originalUrl, res, next));
});

function handleFileNotFound(urlDownload, res, next) {
   return function(error) {
      var fileNotFound = error && error.status === 404;
      if(fileNotFound) {
         var resource = kancolleExternal.kcsResource(urlDownload);
         appLog.info('File not found or not cached');
         appLog.info('Get resource from: ' + resource);
         return agent.download(res, resource, function(response) {
            appLog.info('Download Completed');
            appLog.info('Source URL: ' + resource);
            appLog.debug('Return status code: ' + response.statusCode);
            appLog.debug('Response header: ' + response.headers);
         });
      }
      else if(error) {
         appLog.error(error);
         return next(error);
      }
   }
}

module.exports = exports = router;
{'fraction_non_alphanumeric': 0.15792181069958847, 'fraction_numerical': 0.0030864197530864196, 'mean_word_length': 3.6408114558472553, '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': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1027448', 'n_tokens_mistral': 1191, 'n_tokens_neox': 1168, 'n_words': 252}