<commit_before>"""
Generalized error handling.

"""
from logging import getLogger

from marshmallow import fields, Schema
from werkzeug.exceptions import default_exceptions

from microcosm_flask.conventions.encoding import dump_response_data


error_logger = getLogger("errors")


class SubErrorSchema(Schema):
    message = fields.String(required=True)


class ErrorContextSchema(Schema):
    errors = fields.List(fields.Nested(SubErrorSchema), required=True)


class ErrorSchema(Schema):
    message = fields.String(required=True)
    code = fields.Integer(required=True)
    retryable = fields.Boolean(required=True)
    context = fields.Nested(ErrorContextSchema, required=False)


def as_retryable(error):
    """
    Given an exception, mark it as retryable when serializing
    into transporty layer error response.

    """
    error.retryable = True

    return error
<commit_msg>typo in pydoc on as_retryable<commit_after>"""
Generalized error handling.

"""
from logging import getLogger

from marshmallow import fields, Schema
from werkzeug.exceptions import default_exceptions

from microcosm_flask.conventions.encoding import dump_response_data


error_logger = getLogger("errors")


class SubErrorSchema(Schema):
    message = fields.String(required=True)


class ErrorContextSchema(Schema):
    errors = fields.List(fields.Nested(SubErrorSchema), required=True)


class ErrorSchema(Schema):
    message = fields.String(required=True)
    code = fields.Integer(required=True)
    retryable = fields.Boolean(required=True)
    context = fields.Nested(ErrorContextSchema, required=False)


def as_retryable(error):
    """
    Given an exception, mark it as retryable when serializing
    into HTTP error response.

    """
    error.retryable = True

    return error

{'fraction_non_alphanumeric': 0.08529741863075196, 'fraction_numerical': 0.0, 'mean_word_length': 4.865131578947368, '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': '4407980', 'n_tokens_mistral': 511, 'n_tokens_neox': 502, 'n_words': 129}