# Path: app/extensions/api/http_exceptions.py
# def abort(code, message=None, **kwargs):
#     """
#     Custom abort function used to provide extra information in the error
#     response, namely, ``status`` and ``message`` info.
#     """
#     if message is None:
#         if code in API_DEFAULT_HTTP_CODE_MESSAGES:  # pylint: disable=consider-using-get
#             message = API_DEFAULT_HTTP_CODE_MESSAGES[code]
#         else:
#             message = HTTPStatus(code).description  # pylint: disable=no-value-for-parameter
#     restplus_abort(code=code, status=code, message=message, **kwargs)


from webargs.flaskparser import FlaskParser
from .http_exceptions import abort
# encoding: utf-8
"""
Webargs Parser wrapper module
-----------------------------
"""



class CustomWebargsParser(FlaskParser):
    """
    This custom Webargs Parser aims to overload :meth:``handle_error`` in order
    to call our custom :func:``abort`` function.

    See the following issue and the related PR for more details:
    https://github.com/sloria/webargs/issues/122
    """

    def handle_error(self, error, *args, **kwargs):
        # pylint: disable=arguments-differ
        """
        Handles errors during parsing. Aborts the current HTTP request and
        responds with a 422 error.
        """
        status_code = getattr(error, 'status_code', self.DEFAULT_VALIDATION_STATUS)

# Path: app/extensions/api/http_exceptions.py
# def abort(code, message=None, **kwargs):
#     """
#     Custom abort function used to provide extra information in the error
#     response, namely, ``status`` and ``message`` info.
#     """
#     if message is None:
#         if code in API_DEFAULT_HTTP_CODE_MESSAGES:  # pylint: disable=consider-using-get
#             message = API_DEFAULT_HTTP_CODE_MESSAGES[code]
#         else:
#             message = HTTPStatus(code).description  # pylint: disable=no-value-for-parameter
#     restplus_abort(code=code, status=code, message=message, **kwargs)


# Path: app/extensions/api/webargs_parser.py
from webargs.flaskparser import FlaskParser
from .http_exceptions import abort

# encoding: utf-8
"""
Webargs Parser wrapper module
-----------------------------
"""



class CustomWebargsParser(FlaskParser):
    """
    This custom Webargs Parser aims to overload :meth:``handle_error`` in order
    to call our custom :func:``abort`` function.

    See the following issue and the related PR for more details:
    https://github.com/sloria/webargs/issues/122
    """

    def handle_error(self, error, *args, **kwargs):
        # pylint: disable=arguments-differ
        """
        Handles errors during parsing. Aborts the current HTTP request and
        responds with a 422 error.
        """
        status_code = getattr(error, 'status_code', self.DEFAULT_VALIDATION_STATUS)

        abort(status_code, messages=error.messages)