Skip to content

Commit

Permalink
Introduce some more exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Oderbolz committed Jan 3, 2015
1 parent d9aa5b5 commit 22d8eb3
Showing 1 changed file with 36 additions and 5 deletions.
41 changes: 36 additions & 5 deletions osmapi/OsmApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,29 @@ class UsernamePasswordMissingError(Exception):
pass


class NoChangesetOpenError(Exception):
"""
Error when an operation requires an open changeset, but currently
no changeset _is_ open
"""
pass


class ChangesetAlreadyOpenError(Exception):
"""
Error when a user tries to open a changeset when there is already
an open changeset
"""
pass


class OsmTypeAlreadyExists(Exception):
"""
Error when a user tries to create an object that already exsits
"""
pass


class ApiError(Exception):
"""
Error class, is thrown when an API request fails
Expand All @@ -76,10 +99,18 @@ def __str__(self):


class AlreadySubscribedApiError(ApiError):
"""
Error when a user tries to subscribe to a changeset
that she is already subscribed to
"""
pass


class NotSubscribedApiError(ApiError):
"""
Error when user tries to unsubscribe from a changeset
that he is not subscribed to
"""
pass


Expand Down Expand Up @@ -1063,7 +1094,7 @@ def ChangesetUpdate(self, ChangesetTags={}):
Updates current changeset with `ChangesetTags`.
"""
if not self._CurrentChangesetId:
raise Exception("No changeset currently opened")
raise NoChangesetOpenError("No changeset currently opened")
if "created_by" not in ChangesetTags:
ChangesetTags["created_by"] = self._created_by
self._put(
Expand All @@ -1081,7 +1112,7 @@ def ChangesetCreate(self, ChangesetTags={}):
Returns `ChangesetId`
"""
if self._CurrentChangesetId:
raise Exception("Changeset already opened")
raise ChangesetAlreadyOpenError("Changeset already opened")
if "created_by" not in ChangesetTags:
ChangesetTags["created_by"] = self._created_by
result = self._put(
Expand All @@ -1098,7 +1129,7 @@ def ChangesetClose(self):
Returns `ChangesetId`.
"""
if not self._CurrentChangesetId:
raise Exception("No changeset currently opened")
raise NoChangesetOpenError("No changeset currently opened")
self._put(
"/api/0.6/changeset/"+str(self._CurrentChangesetId)+"/close",
""
Expand Down Expand Up @@ -1642,15 +1673,15 @@ def _do(self, action, OsmType, OsmData):

def _do_manu(self, action, OsmType, OsmData):
if not self._CurrentChangesetId:
raise Exception(
raise NoChangesetOpenError(
"You need to open a changeset before uploading data"
)
if "timestamp" in OsmData:
OsmData.pop("timestamp")
OsmData["changeset"] = self._CurrentChangesetId
if action == "create":
if OsmData.get("id", -1) > 0:
raise Exception("This "+OsmType+" already exists")
raise OsmTypeAlreadyExists("This "+OsmType+" already exists")
result = self._put(
"/api/0.6/" + OsmType + "/create",
self._XmlBuild(OsmType, OsmData)
Expand Down

0 comments on commit 22d8eb3

Please sign in to comment.