"""Helpers for capturing requests exceptions."""

from functools import wraps

from requests import RequestException, exceptions

from via.exceptions import BadURL, UnhandledException, UpstreamServiceError

REQUESTS_BAD_URL = (
    exceptions.MissingSchema,
    exceptions.InvalidSchema,
    exceptions.InvalidURL,
    exceptions.URLRequired,
)
REQUESTS_UPSTREAM_SERVICE = (
    exceptions.ConnectionError,
    exceptions.Timeout,
    exceptions.TooManyRedirects,
    exceptions.SSLError,
)


def handle_errors(inner):
    """Translate errors into our application errors."""

    @wraps(inner)
    def deco(*args, **kwargs):
        try:
            return inner(*args, **kwargs)

        except REQUESTS_BAD_URL as err:
            raise BadURL() from err

        except REQUESTS_UPSTREAM_SERVICE as err:
            raise UpstreamServiceError() from err

        except RequestException as err:
            raise UnhandledException() from err

    return deco


def iter_handle_errors(inner):
    """Translate errors into our application errors."""

    @wraps(inner)
    def deco(*args, **kwargs):
        try:
            yield from inner(*args, **kwargs)

        except REQUESTS_BAD_URL as err:
            raise BadURL(err.args[0]) from None

        except REQUESTS_UPSTREAM_SERVICE as err:
            raise UpstreamServiceError(err.args[0]) from None

        except RequestException as err:
            raise UnhandledException(err.args[0]) from None

    return deco

@@ -486,16 +486,86 @@
 or,%0A)%0A%0A%0A
+def _get_message(err):%0A    return err.args%5B0%5D if err.args else None%0A%0A%0A
 def hand
@@ -809,16 +809,33 @@
  BadURL(
+_get_message(err)
 ) from e
@@ -926,16 +926,33 @@
 ceError(
+_get_message(err)
 ) from e
@@ -1032,16 +1032,33 @@
 ception(
+_get_message(err)
 ) from e
@@ -1341,27 +1341,33 @@
  BadURL(
-err.args%5B0%5D
+_get_message(err)
 ) from N
@@ -1459,27 +1459,33 @@
 ceError(
-err.args%5B0%5D
+_get_message(err)
 ) from N
@@ -1566,27 +1566,33 @@
 ception(
-err.args%5B0%5D
+_get_message(err)
 ) from N

Fix error handling to show error messages