<commit_before>require('./env');
var http = require('http');
var koa = require('koa');
var app = koa();

// Error handling
app.use(function *(next) {
  this.createError = function(err) {
    this.status = err.status || 500;
    this.body = {
      error: err.message,
      type: err.name,
      status: this.status
    };
  };
  try {
    yield next;
  } catch (err) {
    if (err.name === 'SequelizeValidationError') {
      this.createError(new HTTP_ERROR.InvalidParameter(err.errors.map(function(err) {
        return err.message;
      })));
    } else {
      if (err.expose) {
        this.createError(err);
      } else {
        this.status = err.status || 500;
        this.body = { status: this.status };
        console.error(err.stack);
      }
    }
  }
});

// Basic auth
var auth = require('basic-auth');
app.use(function *(next) {
  var token = this.request.get('x-session-token');
  if (token) {
    this.me = yield Session.getUser(token);
    this.assert(this.me, new HTTP_ERROR.InvalidToken());
    this.me.setDataValue('authScope', 'session');
  }
  var user = auth(this.req);
  if (user) {
    this.me = yield User.find({ where: { email: user.name } });
    this.assert(this.me, new HTTP_ERROR.UnregisteredEmail());
    this.assert(yield this.me.comparePassword(user.pass), new HTTP_ERROR.WrongPassword());
    this.me.setDataValue('authScope', 'basic-auth');
  }
  if (!this.me) {
    Object.defineProperty(this, 'me', {
      get: function() {
        this.throw(new HTTP_ERROR.Unauthorized());<commit_msg>Log the error message<commit_after>require('./env');
var http = require('http');
var koa = require('koa');
var app = koa();

// Error handling
app.use(function *(next) {
  this.createError = function(err) {
    this.status = err.status || 500;
    this.body = {
      error: err.message,
      type: err.name,
      status: this.status
    };
  };
  try {
    yield next;
  } catch (err) {
    if (err.name === 'SequelizeValidationError') {
      this.createError(new HTTP_ERROR.InvalidParameter(err.errors.map(function(err) {
        return err.message;
      })));
    } else {
      if (err.expose) {
        this.createError(err);
      } else {
        this.status = err.status || 500;
        this.body = { status: this.status };
        console.error(err, err.stack);
      }
    }
  }
});

// Basic auth
var auth = require('basic-auth');
app.use(function *(next) {
  var token = this.request.get('x-session-token');
  if (token) {
    this.me = yield Session.getUser(token);
    this.assert(this.me, new HTTP_ERROR.InvalidToken());
    this.me.setDataValue('authScope', 'session');
  }
  var user = auth(this.req);
  if (user) {
    this.me = yield User.find({ where: { email: user.name } });
    this.assert(this.me, new HTTP_ERROR.UnregisteredEmail());
    this.assert(yield this.me.comparePassword(user.pass), new HTTP_ERROR.WrongPassword());
    this.me.setDataValue('authScope', 'basic-auth');
  }
  if (!this.me) {
    Object.defineProperty(this, 'me', {
      get: function() {
        this.throw(new HTTP_ERROR.Unauthorized());
{'fraction_non_alphanumeric': 0.16954116498535632, 'fraction_numerical': 0.0039049788480312398, 'mean_word_length': 2.8569636135508154, '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': '1140775', 'n_tokens_mistral': 1034, 'n_tokens_neox': 1017, 'n_words': 199}