From fdeaf54aa9c49e9ae24510601f5903ca31eeaba8 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 20 Jan 2021 16:32:00 +0100 Subject: [PATCH] API - refactor exceptions --- fittrackee/email/exceptions.py | 2 ++ fittrackee/email/utils_email.py | 4 +--- fittrackee/exceptions.py | 11 +++++++++++ fittrackee/workouts/exceptions.py | 9 +++++++++ fittrackee/workouts/utils.py | 10 +--------- fittrackee/workouts/utils_gpx.py | 10 +--------- 6 files changed, 25 insertions(+), 21 deletions(-) create mode 100644 fittrackee/email/exceptions.py create mode 100644 fittrackee/exceptions.py create mode 100644 fittrackee/workouts/exceptions.py diff --git a/fittrackee/email/exceptions.py b/fittrackee/email/exceptions.py new file mode 100644 index 00000000..8fee33b4 --- /dev/null +++ b/fittrackee/email/exceptions.py @@ -0,0 +1,2 @@ +class InvalidEmailUrlScheme(Exception): + ... diff --git a/fittrackee/email/utils_email.py b/fittrackee/email/utils_email.py index 1daa2ab3..4721a63d 100644 --- a/fittrackee/email/utils_email.py +++ b/fittrackee/email/utils_email.py @@ -2,9 +2,7 @@ from typing import Dict from urllib3.util import parse_url - -class InvalidEmailUrlScheme(Exception): - ... +from .exceptions import InvalidEmailUrlScheme def parse_email_url(email_url: str) -> Dict: diff --git a/fittrackee/exceptions.py b/fittrackee/exceptions.py new file mode 100644 index 00000000..4ec38e3d --- /dev/null +++ b/fittrackee/exceptions.py @@ -0,0 +1,11 @@ +from typing import Optional + + +class GenericException(Exception): + def __init__( + self, status: str, message: str, e: Optional[Exception] = None + ) -> None: + super().__init__(message) + self.status = status + self.message = message + self.e = e diff --git a/fittrackee/workouts/exceptions.py b/fittrackee/workouts/exceptions.py new file mode 100644 index 00000000..2aa1cc4f --- /dev/null +++ b/fittrackee/workouts/exceptions.py @@ -0,0 +1,9 @@ +from fittrackee.exceptions import GenericException + + +class WorkoutException(GenericException): + ... + + +class WorkoutGPXException(GenericException): + ... diff --git a/fittrackee/workouts/utils.py b/fittrackee/workouts/utils.py index 5e2c4895..cd062b6e 100644 --- a/fittrackee/workouts/utils.py +++ b/fittrackee/workouts/utils.py @@ -16,20 +16,12 @@ from werkzeug.datastructures import FileStorage from werkzeug.utils import secure_filename from ..users.models import User +from .exceptions import WorkoutException from .models import Sport, Workout, WorkoutSegment from .utils_files import get_absolute_file_path from .utils_gpx import get_gpx_info -class WorkoutException(Exception): - def __init__( - self, status: str, message: str, e: Optional[Exception] = None - ) -> None: - self.status = status - self.message = message - self.e = e - - def get_datetime_with_tz( timezone: str, workout_date: datetime, gpx_data: Optional[Dict] = None ) -> Tuple[Optional[datetime], datetime]: diff --git a/fittrackee/workouts/utils_gpx.py b/fittrackee/workouts/utils_gpx.py index c92153b0..84ec47f1 100644 --- a/fittrackee/workouts/utils_gpx.py +++ b/fittrackee/workouts/utils_gpx.py @@ -3,18 +3,10 @@ from typing import Any, Dict, List, Optional, Tuple import gpxpy.gpx +from .exceptions import WorkoutGPXException from .utils_weather import get_weather -class WorkoutGPXException(Exception): - def __init__( - self, status: str, message: str, e: Optional[Exception] = None - ) -> None: - self.status = status - self.message = message - self.e = e - - def open_gpx_file(gpx_file: str) -> Optional[gpxpy.gpx.GPX]: gpx_file = open(gpx_file, 'r') # type: ignore gpx = gpxpy.parse(gpx_file)