<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import json
import psycopg2
import psycopg2.extras
import re
import datetime
import os

pg_connect_str = "dbname=bankapi"
pg_conn = None

debug_incoming_data = False
debug_path = '/tmp/bankapi'

def respond(result=None, error=None, httperrorcode=None):
    global pg_conn

    if result is not None:
        data =  """Status: 200 OK
Content-Type: text/plain

""" + result
    else:
        if httperrorcode is None:
            httperrorcode = 500
        if error is None:
            error = 'Unknown error'

        data = "Status: %s %s" % (httperrorcode, error)

    print data
    debug_request('out', data)

    if pg_conn is not None:
        pg_conn.close()
<commit_msg>Correct the error responses so we do not get HTTP 500 for all errors.<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import json
import psycopg2
import psycopg2.extras
import re
import datetime
import os

pg_connect_str = "dbname=bankapi"
pg_conn = None

debug_incoming_data = False
debug_path = '/tmp/bankapi'

def respond(result=None, error=None, httperrorcode=None):
    global pg_conn

    if result is not None:
        data =  """Status: 200 OK
Content-Type: text/plain

""" + result
    else:
        if httperrorcode is None:
            httperrorcode = 500
        if error is None:
            error = 'Unknown error'

        data = """Status: %s %s
""" % (httperrorcode, error)

    print data
    debug_request('out', data)

    if pg_conn is not None:
        pg_conn.close()

{'fraction_non_alphanumeric': 0.1001914486279515, 'fraction_numerical': 0.013401403956604978, 'mean_word_length': 2.769230769230769, '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': '1593969', 'n_tokens_mistral': 533, 'n_tokens_neox': 506, 'n_words': 161}