API - refactor exceptions
This commit is contained in:
parent
d0475eec9f
commit
fdeaf54aa9
2
fittrackee/email/exceptions.py
Normal file
2
fittrackee/email/exceptions.py
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
class InvalidEmailUrlScheme(Exception):
|
||||||
|
...
|
@ -2,9 +2,7 @@ from typing import Dict
|
|||||||
|
|
||||||
from urllib3.util import parse_url
|
from urllib3.util import parse_url
|
||||||
|
|
||||||
|
from .exceptions import InvalidEmailUrlScheme
|
||||||
class InvalidEmailUrlScheme(Exception):
|
|
||||||
...
|
|
||||||
|
|
||||||
|
|
||||||
def parse_email_url(email_url: str) -> Dict:
|
def parse_email_url(email_url: str) -> Dict:
|
||||||
|
11
fittrackee/exceptions.py
Normal file
11
fittrackee/exceptions.py
Normal 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
|
9
fittrackee/workouts/exceptions.py
Normal file
9
fittrackee/workouts/exceptions.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
from fittrackee.exceptions import GenericException
|
||||||
|
|
||||||
|
|
||||||
|
class WorkoutException(GenericException):
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
|
class WorkoutGPXException(GenericException):
|
||||||
|
...
|
@ -16,20 +16,12 @@ from werkzeug.datastructures import FileStorage
|
|||||||
from werkzeug.utils import secure_filename
|
from werkzeug.utils import secure_filename
|
||||||
|
|
||||||
from ..users.models import User
|
from ..users.models import User
|
||||||
|
from .exceptions import WorkoutException
|
||||||
from .models import Sport, Workout, WorkoutSegment
|
from .models import Sport, Workout, WorkoutSegment
|
||||||
from .utils_files import get_absolute_file_path
|
from .utils_files import get_absolute_file_path
|
||||||
from .utils_gpx import get_gpx_info
|
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(
|
def get_datetime_with_tz(
|
||||||
timezone: str, workout_date: datetime, gpx_data: Optional[Dict] = None
|
timezone: str, workout_date: datetime, gpx_data: Optional[Dict] = None
|
||||||
) -> Tuple[Optional[datetime], datetime]:
|
) -> Tuple[Optional[datetime], datetime]:
|
||||||
|
@ -3,18 +3,10 @@ from typing import Any, Dict, List, Optional, Tuple
|
|||||||
|
|
||||||
import gpxpy.gpx
|
import gpxpy.gpx
|
||||||
|
|
||||||
|
from .exceptions import WorkoutGPXException
|
||||||
from .utils_weather import get_weather
|
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]:
|
def open_gpx_file(gpx_file: str) -> Optional[gpxpy.gpx.GPX]:
|
||||||
gpx_file = open(gpx_file, 'r') # type: ignore
|
gpx_file = open(gpx_file, 'r') # type: ignore
|
||||||
gpx = gpxpy.parse(gpx_file)
|
gpx = gpxpy.parse(gpx_file)
|
||||||
|
Loading…
Reference in New Issue
Block a user