1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
# -*- coding: utf-8 -*-
class OsmApiError(Exception):
"""
General OsmApi error class to provide a superclass for all other errors
"""
class MaximumRetryLimitReachedError(OsmApiError):
"""
Error when the maximum amount of retries is reached and we have to give up
"""
class UsernamePasswordMissingError(OsmApiError):
"""
Error when username or password is missing for an authenticated request
"""
pass
class NoChangesetOpenError(OsmApiError):
"""
Error when an operation requires an open changeset, but currently
no changeset _is_ open
"""
pass
class ChangesetAlreadyOpenError(OsmApiError):
"""
Error when a user tries to open a changeset when there is already
an open changeset
"""
pass
class OsmTypeAlreadyExistsError(OsmApiError):
"""
Error when a user tries to create an object that already exsits
"""
pass
class XmlResponseInvalidError(OsmApiError):
"""
Error if the XML response from the OpenStreetMap API is invalid
"""
class ApiError(OsmApiError):
"""
Error class, is thrown when an API request fails
"""
def __init__(self, status, reason, payload):
self.status = status
"""HTTP error code"""
self.reason = reason
"""Error message"""
self.payload = payload
"""Payload of API when this error occured"""
def __str__(self):
return (
"Request failed: %s - %s - %s"
% (str(self.status), self.reason, self.payload)
)
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
class ElementDeletedApiError(ApiError):
"""
Error when the requested element is deleted
"""
pass
class ElementNotFoundApiError(ApiError):
"""
Error if the the requested element was not found
"""
class ResponseEmptyApiError(ApiError):
"""
Error when the response to the request is empty
"""
pass
class ChangesetClosedApiError(ApiError):
"""
Error if the the changeset in question has already been closed
"""
class NoteAlreadyClosedApiError(ApiError):
"""
Error if the the note in question has already been closed
"""
class VersionMismatchApiError(ApiError):
"""
Error if the provided version does not match the database version
of the element
"""
class PreconditionFailedApiError(ApiError):
"""
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
"""
|