<commit_before>require 'sinatra/base'
require 'sinatra/activerecord'

require 'duse/api/errors'
require 'duse/api/authorization'
require 'duse/api/v1/helpers'
require 'duse/api'

module Duse
  module API
    module V1
      class Base < Sinatra::Base
        set :database, ENV['DATABASE_URL']
        set :database_extras, { pool: 5, timeout: 3000, encoding: 'unicode' }
        enable :dump_errors
        disable :raise_errors
        disable :show_exceptions # disable middleware displaying errors as html

        helpers Helpers
        register Sinatra::ActiveRecordExtension

        error MalformedJSON, AlreadyConfirmed do
          halt 400, { message: env['sinatra.error'].message }.to_json
        end

        error UserNotConfirmed do
          env['warden'].custom_failure!
          halt 401, { message: 'User not confirmed' }.to_json
        end

        error InvalidAuthorization do
          halt 403, { message: 'You are not authorized to access a resource' }.to_json
        end

        error Duse::API::NotFound do
          halt 404
        end

        not_found do
          { message: 'Not found' }.to_json
        end

        error ValidationFailed do
          halt 422, env['sinatra.error'].message
        end

        error do
          Raven.capture_exception env['sinatra.error']
          puts env['sinatra.error']
          puts env['sinatra.error'].backtrace
          halt 500, JSON.generate(message: 'Whoops, an error occured in duse')
        end
      end
    end
  end
end
<commit_msg>remove exception logging to stdout<commit_after>require 'sinatra/base'
require 'sinatra/activerecord'

require 'duse/api/errors'
require 'duse/api/authorization'
require 'duse/api/v1/helpers'
require 'duse/api'

module Duse
  module API
    module V1
      class Base < Sinatra::Base
        set :database, ENV['DATABASE_URL']
        set :database_extras, { pool: 5, timeout: 3000, encoding: 'unicode' }
        enable :dump_errors
        disable :raise_errors
        disable :show_exceptions # disable middleware displaying errors as html

        helpers Helpers
        register Sinatra::ActiveRecordExtension

        error MalformedJSON, AlreadyConfirmed do
          halt 400, { message: env['sinatra.error'].message }.to_json
        end

        error UserNotConfirmed do
          env['warden'].custom_failure!
          halt 401, { message: 'User not confirmed' }.to_json
        end

        error InvalidAuthorization do
          halt 403, { message: 'You are not authorized to access a resource' }.to_json
        end

        error Duse::API::NotFound do
          halt 404
        end

        not_found do
          { message: 'Not found' }.to_json
        end

        error ValidationFailed do
          halt 422, env['sinatra.error'].message
        end

        error do
          Raven.capture_exception env['sinatra.error']
          halt 500, JSON.generate(message: 'Whoops, an error occured in duse')
        end
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.07969323107702568, 'fraction_numerical': 0.016672224074691565, 'mean_word_length': 2.2467532467532467, 'pattern_counts': {'":': 0, '<': 5, '<?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': '7022642', 'n_tokens_mistral': 902, 'n_tokens_neox': 833, 'n_words': 256}