Extract exceptions - toot - Unnamed repository; edit this file 'description' to name the repository.
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) LICENSE
---
(DIR) commit 7bbc98363edfb64ca7e07bbe1dab7b46ab1210bd
(DIR) parent 177af4fac959be2a22940d141feab4f8848379c5
(HTM) Author: Ivan Habunek <ivan@habunek.com>
Date: Sat, 30 Dec 2017 13:32:52 +0100
Extract exceptions
Diffstat:
tests/test_console.py | 3 ++-
toot/__init__.py | 4 ----
toot/api.py | 13 +------------
toot/app.py | 2 +-
toot/auth.py | 5 +++--
toot/commands.py | 3 ++-
toot/console.py | 5 +++--
toot/exceptions.py | 14 ++++++++++++++
8 files changed, 26 insertions(+), 23 deletions(-)
---
(DIR) diff --git a/tests/test_console.py b/tests/test_console.py
@@ -3,7 +3,8 @@ import pytest
import requests
import re
-from toot import console, User, App, ConsoleError
+from toot import console, User, App
+from toot.exceptions import ConsoleError
from tests.utils import MockResponse
(DIR) diff --git a/toot/__init__.py b/toot/__init__.py
@@ -9,7 +9,3 @@ DEFAULT_INSTANCE = 'mastodon.social'
CLIENT_NAME = 'toot - a Mastodon CLI client'
CLIENT_WEBSITE = 'https://github.com/ihabunek/toot'
-
-
-class ConsoleError(Exception):
- pass
(DIR) diff --git a/toot/api.py b/toot/api.py
@@ -9,22 +9,11 @@ from urllib.parse import urlparse, urlencode
from toot import CLIENT_NAME, CLIENT_WEBSITE
from toot.utils import domain_exists
from toot.logging import log_request, log_response
+from toot.exceptions import ApiError, AuthenticationError, NotFoundError
SCOPES = 'read write follow'
-class ApiError(Exception):
- pass
-
-
-class NotFoundError(ApiError):
- pass
-
-
-class AuthenticationError(ApiError):
- pass
-
-
def _process_response(response):
log_response(response)
(DIR) diff --git a/toot/app.py b/toot/app.py
@@ -4,7 +4,7 @@ import webbrowser
from textwrap import wrap
-from toot import ConsoleError
+from toot.exceptions import ConsoleError
from toot.utils import format_content
# Attempt to load curses, which is not available on windows
(DIR) diff --git a/toot/auth.py b/toot/auth.py
@@ -5,7 +5,8 @@ import webbrowser
from builtins import input
from getpass import getpass
-from toot import api, config, DEFAULT_INSTANCE, User, App, ConsoleError
+from toot import api, config, DEFAULT_INSTANCE, User, App
+from toot.exceptions import ApiError, ConsoleError
from toot.output import print_out
@@ -59,7 +60,7 @@ def login_interactive(app, email=None):
try:
print_out("Authenticating...")
response = api.login(app, email, password)
- except api.ApiError:
+ except ApiError:
raise ConsoleError("Login failed")
return create_user(app, email, response['access_token'])
(DIR) diff --git a/toot/commands.py b/toot/commands.py
@@ -6,8 +6,9 @@ from itertools import zip_longest
from itertools import chain
from textwrap import TextWrapper
-from toot import api, config, ConsoleError
+from toot import api, config
from toot.auth import login_interactive, login_browser_interactive, create_app_interactive
+from toot.exceptions import ConsoleError
from toot.output import print_out, print_instance, print_account, print_search_results
(DIR) diff --git a/toot/console.py b/toot/console.py
@@ -5,7 +5,8 @@ import logging
from argparse import ArgumentParser, FileType
from collections import namedtuple
-from toot import config, api, commands, ConsoleError, CLIENT_NAME, CLIENT_WEBSITE
+from toot import config, commands, CLIENT_NAME, CLIENT_WEBSITE
+from toot.exceptions import ApiError, ConsoleError
from toot.output import print_out, print_err
@@ -311,6 +312,6 @@ def main():
except ConsoleError as e:
print_err(str(e))
sys.exit(1)
- except api.ApiError as e:
+ except ApiError as e:
print_err(str(e))
sys.exit(1)
(DIR) diff --git a/toot/exceptions.py b/toot/exceptions.py
@@ -0,0 +1,14 @@
+class ApiError(Exception):
+ """Raised when an API request fails for whatever reason."""
+
+
+class NotFoundError(ApiError):
+ """Raised when an API requests returns a 404."""
+
+
+class AuthenticationError(ApiError):
+ """Raised when login fails."""
+
+
+class ConsoleError(Exception):
+ """Raised when an error occurs which needs to be show to the user."""