<commit_before>const router = require('koa-router')()
const handlebars = require('koa-handlebars')
const Page = require('../models/page')

var details = {
  site: {
    title: '<NAME>'
  },
  year: new Date().getFullYear()
}

router.use(function *(next) {
  try {
    var pages = yield Page.find()
  } catch (err) {
    throw err
  }

  for (var page in pages) {
    pages[page] = pages[page].toObject()
  }

  this.pages = pages
  yield next
})

router.get('*', function *(next) {
  details.site.canonical = this.request.origin
  const path = this.request.url

  details.pages = this.pages

  try {
    const result = yield Page.findOne({
      slug: path.split('/')[1]
    })
  } catch (err) {
    throw err
  }

  if (!result) {
    this.body = '404 - Not found'
    return next
  }

  Object.assign(details, result.toObject())

  if (path === '/') {
    yield this.render('index', details)
    return next
  }

  yield this.render('page', details)<commit_msg>Let koa handle errors<commit_after>const router = require('koa-router')()
const handlebars = require('koa-handlebars')
const Page = require('../models/page')

var details = {
  site: {
    title: '<NAME>'
  },
  year: new Date().getFullYear()
}

router.use(function *(next) {
  try {
    var pages = yield Page.find()
  } catch (err) {
    throw err
  }

  for (var page in pages) {
    pages[page] = pages[page].toObject()
  }

  this.pages = pages
  yield next
})

router.get('*', function *(next) {
  details.site.canonical = this.request.origin
  const path = this.request.url

  details.pages = this.pages

  try {
    const result = yield Page.findOne({
      slug: path.split('/')[1]
    })
  } catch (err) {
    throw err
  }

  if (!result) {
    return next
  }

  Object.assign(details, result.toObject())

  if (path === '/') {
    yield this.render('index', details)
    return next
  }

  yield this.render('page', details)
{'fraction_non_alphanumeric': 0.16263157894736843, 'fraction_numerical': 0.002631578947368421, 'mean_word_length': 2.848178137651822, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1261568', 'n_tokens_mistral': 663, 'n_tokens_neox': 641, 'n_words': 158}