<commit_before>/**
 * Created by sunfuze on 10/14/16.
 */
'use strict'
const { omit } = require('lodash')

module.exports = function (app) {
  const context = app.context

  const _onerror = context.onerror

  context.onerror = function (err = {}) {
    if (err === null) return
    if (err.code) {
      if (this.headerSent || !this.writable) {
        err.headerSent = true
        return
      }

      this.type = 'json'

      let code = err.code
      while (code >= 1000) {
        code = code / 10 >> 0
      }
      this.status = code

      let body = omit(err, ['name', 'stack'])
      // using i18next
      if (this.i18next && typeof this.t === 'function') {
        for (let key in body) {
          if (body.hasOwnProperty[key] && typeof body[key] === 'string') {
            body[key] = this.t(body[key])
          }
        }
      }
      body = JSON.stringify(body)
      this.length = Buffer.byteLength(body)
      return this.res.end(body)<commit_msg>fix: remove , ,  in error body<commit_after>/**
 * Created by sunfuze on 10/14/16.
 */
'use strict'
const { omit } = require('lodash')

module.exports = function (app) {
  const context = app.context

  const _onerror = context.onerror

  context.onerror = function (err = {}) {
    if (err === null) return
    if (err.code) {
      if (this.headerSent || !this.writable) {
        err.headerSent = true
        return
      }

      this.type = 'json'

      let code = err.code
      while (code >= 1000) {
        code = code / 10 >> 0
      }
      this.status = code

      let body = omit(err, ['name', 'stack', 'status', 'statusCode', 'expose'])
      // using i18next
      if (this.i18next && typeof this.t === 'function') {
        for (let key in body) {
          if (body.hasOwnProperty[key] && typeof body[key] === 'string') {
            body[key] = this.t(body[key])
          }
        }
      }
      body = JSON.stringify(body)
      this.length = Buffer.byteLength(body)
      return this.res.end(body)
{'fraction_non_alphanumeric': 0.1493734335839599, 'fraction_numerical': 0.017042606516290727, 'mean_word_length': 2.001503759398496, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '5342066', 'n_tokens_mistral': 678, 'n_tokens_neox': 638, 'n_words': 164}