Skip to content

Commit

Permalink
Renamed error classes
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaspasser committed Mar 11, 2020
1 parent 7e689f0 commit 9b7cb50
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion rjpl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from rjpl.methods import location, trip, departureBoard, multiDepartureBoard, stopsNearby
from rjpl.classes import Coord, Stop, ConnectionError, HTTPError, APIError
from rjpl.classes import Coord, Stop, rjplConnectionError, rjplHTTPError, rjplAPIError
6 changes: 3 additions & 3 deletions rjpl/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ def __init__(self, stop_id):
raise TypeError("Expected <class 'int'> got {}.".format(type(stop_id)))


class APIError(Exception):
class rjplAPIError(Exception):
"""Raised when the API returned an error."""
pass

class ConnectionError(Exception):
class rjplConnectionError(Exception):
"""Raised in the event of a network problem."""
pass

class HTTPError(Exception):
class rjplHTTPError(Exception):
"""Raised when the HTTP response code is not 200."""
pass
14 changes: 7 additions & 7 deletions rjpl/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ def _request(service, params, timeout):
try:
response = requests.get(RESOURCE+service, params, timeout=timeout)
except requests.exceptions.RequestException as e:
raise ConnectionError(e)
raise rjplConnectionError(e)

if response.status_code == 200:
return response.json()
else:
raise HTTPError('Error: ' + str(response.status_code) +
raise rjplHTTPError('Error: ' + str(response.status_code) +
str(response.content))

def location(input, timeout=5):
Expand Down Expand Up @@ -50,7 +50,7 @@ def location(input, timeout=5):
result = response['LocationList']

if 'error' in result:
raise APIError(result['error'])
raise rjplAPIError(result['error'])

return result

Expand Down Expand Up @@ -197,7 +197,7 @@ def trip(origin, destination, viaId=None, time=None, searchForArrival=None, useT

result = response['TripList']
if 'error' in result:
raise APIError(result['error'])
raise rjplAPIError(result['error'])

return result['Trip']

Expand Down Expand Up @@ -261,7 +261,7 @@ def departureBoard(stop_id, useTrain=True, useBus=True, useMetro=True, time=None

# This key is present on error
if 'error' in result:
raise APIError(result['error'])
raise rjplAPIError(result['error'])

return result['Departure']

Expand Down Expand Up @@ -329,7 +329,7 @@ def multiDepartureBoard(*ids, **args):
result = response['MultiDepartureBoard']

if 'error' in result:
raise APIError(result['error'])
raise rjplAPIError(result['error'])

return result['Departure']

Expand Down Expand Up @@ -373,7 +373,7 @@ def stopsNearby(coordX, coordY, maxRadius=None, maxNumber=None, timeout=5):

result = response['LocationList']
if 'error' in result:
raise APIError(result['error'])
raise rjplAPIError(result['error'])
return result['StopLocation']


Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
setup(
name = 'rjpl',
packages = ['rjpl'],
version = '0.3.4',
version = '0.3.5',
license='MIT',
description = 'Interface with Rejseplanen API',
long_description=long_description,
long_description_content_type='text/markdown',
author = 'Thomas Passer Jensen',
author_email = '[email protected]',
url = 'https://github.com/tomatpasser/python-rejseplanen',
download_url = 'https://github.com/tomatpasser/python-rejseplanen/archive/v0.3.4.tar.gz',
download_url = 'https://github.com/tomatpasser/python-rejseplanen/archive/v0.3.5.tar.gz',
keywords = ['transport', 'rejseplanen', 'timetable', 'journey', 'public transport'],
install_requires=[
'requests>=2.9.1',
Expand Down

0 comments on commit 9b7cb50

Please sign in to comment.