osmapi.errors
Error classes for the OpenStreetMap API.
1""" 2Error classes for the OpenStreetMap API.""" 3 4from typing import Any 5 6 7class OsmApiError(Exception): 8 """ 9 General OsmApi error class to provide a superclass for all other errors 10 """ 11 12 13class MaximumRetryLimitReachedError(OsmApiError): 14 """ 15 Error when the maximum amount of retries is reached and we have to give up 16 """ 17 18 19class UsernamePasswordMissingError(OsmApiError): 20 """ 21 Error when username or password is missing for an authenticated request 22 """ 23 24 pass 25 26 27class NoChangesetOpenError(OsmApiError): 28 """ 29 Error when an operation requires an open changeset, but currently 30 no changeset _is_ open 31 """ 32 33 pass 34 35 36class ChangesetAlreadyOpenError(OsmApiError): 37 """ 38 Error when a user tries to open a changeset when there is already 39 an open changeset 40 """ 41 42 pass 43 44 45class OsmTypeAlreadyExistsError(OsmApiError): 46 """ 47 Error when a user tries to create an object that already exsits 48 """ 49 50 pass 51 52 53class XmlResponseInvalidError(OsmApiError): 54 """ 55 Error if the XML response from the OpenStreetMap API is invalid 56 """ 57 58 59class ApiError(OsmApiError): 60 """ 61 Error class, is thrown when an API request fails 62 """ 63 64 def __init__(self, status: int, reason: str, payload: Any) -> None: 65 self.status = status 66 """HTTP error code""" 67 68 self.reason = reason 69 """Error message""" 70 71 self.payload = payload 72 """Payload of API when this error occured""" 73 74 def __str__(self) -> str: 75 return f"Request failed: {self.status} - {self.reason} - {self.payload}" 76 77 78class UnauthorizedApiError(ApiError): 79 """ 80 Error when the API returned an Unauthorized error, 81 e.g. when the provided OAuth token is expired 82 """ 83 84 pass 85 86 87class AlreadySubscribedApiError(ApiError): 88 """ 89 Error when a user tries to subscribe to a changeset 90 that she is already subscribed to 91 """ 92 93 pass 94 95 96class NotSubscribedApiError(ApiError): 97 """ 98 Error when user tries to unsubscribe from a changeset 99 that he is not subscribed to 100 """ 101 102 pass 103 104 105class ElementDeletedApiError(ApiError): 106 """ 107 Error when the requested element is deleted 108 """ 109 110 pass 111 112 113class ElementNotFoundApiError(ApiError): 114 """ 115 Error if the the requested element was not found 116 """ 117 118 119class ResponseEmptyApiError(ApiError): 120 """ 121 Error when the response to the request is empty 122 """ 123 124 pass 125 126 127class ChangesetClosedApiError(ApiError): 128 """ 129 Error if the the changeset in question has already been closed 130 """ 131 132 133class NoteAlreadyClosedApiError(ApiError): 134 """ 135 Error if the the note in question has already been closed 136 """ 137 138 139class VersionMismatchApiError(ApiError): 140 """ 141 Error if the provided version does not match the database version 142 of the element 143 """ 144 145 146class PreconditionFailedApiError(ApiError): 147 """ 148 Error if the precondition of the operation was not met: 149 - When a way has nodes that do not exist or are not visible 150 - When a relation has elements that do not exist or are not visible 151 - When a node/way/relation is still used in a way/relation 152 """ 153 154 155class TimeoutApiError(ApiError): 156 """ 157 Error if the http request ran into a timeout 158 """ 159 160 161class ConnectionApiError(ApiError): 162 """ 163 Error if there was a network error (e.g. DNS failure, refused connection) 164 while connecting to the remote server. 165 """
8class OsmApiError(Exception): 9 """ 10 General OsmApi error class to provide a superclass for all other errors 11 """
General OsmApi error class to provide a superclass for all other errors
Inherited Members
- builtins.Exception
- Exception
- builtins.BaseException
- with_traceback
- add_note
- args
14class MaximumRetryLimitReachedError(OsmApiError): 15 """ 16 Error when the maximum amount of retries is reached and we have to give up 17 """
Error when the maximum amount of retries is reached and we have to give up
Inherited Members
- builtins.Exception
- Exception
- builtins.BaseException
- with_traceback
- add_note
- args
20class UsernamePasswordMissingError(OsmApiError): 21 """ 22 Error when username or password is missing for an authenticated request 23 """ 24 25 pass
Error when username or password is missing for an authenticated request
Inherited Members
- builtins.Exception
- Exception
- builtins.BaseException
- with_traceback
- add_note
- args
28class NoChangesetOpenError(OsmApiError): 29 """ 30 Error when an operation requires an open changeset, but currently 31 no changeset _is_ open 32 """ 33 34 pass
Error when an operation requires an open changeset, but currently no changeset _is_ open
Inherited Members
- builtins.Exception
- Exception
- builtins.BaseException
- with_traceback
- add_note
- args
37class ChangesetAlreadyOpenError(OsmApiError): 38 """ 39 Error when a user tries to open a changeset when there is already 40 an open changeset 41 """ 42 43 pass
Error when a user tries to open a changeset when there is already an open changeset
Inherited Members
- builtins.Exception
- Exception
- builtins.BaseException
- with_traceback
- add_note
- args
46class OsmTypeAlreadyExistsError(OsmApiError): 47 """ 48 Error when a user tries to create an object that already exsits 49 """ 50 51 pass
Error when a user tries to create an object that already exsits
Inherited Members
- builtins.Exception
- Exception
- builtins.BaseException
- with_traceback
- add_note
- args
54class XmlResponseInvalidError(OsmApiError): 55 """ 56 Error if the XML response from the OpenStreetMap API is invalid 57 """
Error if the XML response from the OpenStreetMap API is invalid
Inherited Members
- builtins.Exception
- Exception
- builtins.BaseException
- with_traceback
- add_note
- args
60class ApiError(OsmApiError): 61 """ 62 Error class, is thrown when an API request fails 63 """ 64 65 def __init__(self, status: int, reason: str, payload: Any) -> None: 66 self.status = status 67 """HTTP error code""" 68 69 self.reason = reason 70 """Error message""" 71 72 self.payload = payload 73 """Payload of API when this error occured""" 74 75 def __str__(self) -> str: 76 return f"Request failed: {self.status} - {self.reason} - {self.payload}"
Error class, is thrown when an API request fails
Inherited Members
- builtins.BaseException
- with_traceback
- add_note
- args
88class AlreadySubscribedApiError(ApiError): 89 """ 90 Error when a user tries to subscribe to a changeset 91 that she is already subscribed to 92 """ 93 94 pass
Error when a user tries to subscribe to a changeset that she is already subscribed to
97class NotSubscribedApiError(ApiError): 98 """ 99 Error when user tries to unsubscribe from a changeset 100 that he is not subscribed to 101 """ 102 103 pass
Error when user tries to unsubscribe from a changeset that he is not subscribed to
106class ElementDeletedApiError(ApiError): 107 """ 108 Error when the requested element is deleted 109 """ 110 111 pass
Error when the requested element is deleted
114class ElementNotFoundApiError(ApiError): 115 """ 116 Error if the the requested element was not found 117 """
Error if the the requested element was not found
120class ResponseEmptyApiError(ApiError): 121 """ 122 Error when the response to the request is empty 123 """ 124 125 pass
Error when the response to the request is empty
128class ChangesetClosedApiError(ApiError): 129 """ 130 Error if the the changeset in question has already been closed 131 """
Error if the the changeset in question has already been closed
134class NoteAlreadyClosedApiError(ApiError): 135 """ 136 Error if the the note in question has already been closed 137 """
Error if the the note in question has already been closed
140class VersionMismatchApiError(ApiError): 141 """ 142 Error if the provided version does not match the database version 143 of the element 144 """
Error if the provided version does not match the database version of the element
147class PreconditionFailedApiError(ApiError): 148 """ 149 Error if the precondition of the operation was not met: 150 - When a way has nodes that do not exist or are not visible 151 - When a relation has elements that do not exist or are not visible 152 - When a node/way/relation is still used in a way/relation 153 """
Error if the precondition of the operation was not met:
- When a way has nodes that do not exist or are not visible
- When a relation has elements that do not exist or are not visible
- When a node/way/relation is still used in a way/relation
156class TimeoutApiError(ApiError): 157 """ 158 Error if the http request ran into a timeout 159 """
Error if the http request ran into a timeout
162class ConnectionApiError(ApiError): 163 """ 164 Error if there was a network error (e.g. DNS failure, refused connection) 165 while connecting to the remote server. 166 """
Error if there was a network error (e.g. DNS failure, refused connection) while connecting to the remote server.