API - refactor exceptions

This commit is contained in:
Sam 2021-01-20 16:32:00 +01:00
parent d0475eec9f
commit fdeaf54aa9
6 changed files with 25 additions and 21 deletions

View File

@ -0,0 +1,2 @@
class InvalidEmailUrlScheme(Exception):
...

View File

@ -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:

11
fittrackee/exceptions.py Normal file
View File

@ -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

View File

@ -0,0 +1,9 @@
from fittrackee.exceptions import GenericException
class WorkoutException(GenericException):
...
class WorkoutGPXException(GenericException):
...

View File

@ -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]:

View File

@ -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)