Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions authentik/lib/sync/outgoing/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,61 @@
from json import JSONDecodeError

from authentik.lib.sentry import SentryIgnoredException


class BaseSyncException(SentryIgnoredException):
"""Base class for all sync exceptions"""

error_prefix = "Sync error"
error_default = "Error communicating with remote system"

def __init__(self, response=None):
super().__init__()
self.response = response

def __str__(self):
if self.response is not None:
if hasattr(self.response, "json"):
try:
return f"{self.error_prefix}: {self.response.json()}"
except JSONDecodeError:
pass
if hasattr(self.response, "text"):
return f"{self.error_prefix}: {self.response.text}"
return f"{self.error_prefix}: {self.response}"
return self.error_default

def __repr__(self):
return self.__str__()


class TransientSyncException(BaseSyncException):
"""Transient sync exception which may be caused by network blips, etc"""

error_prefix = "Network error"
error_default = "Network error communicating with remote system"


class NotFoundSyncException(BaseSyncException):
"""Exception when an object was not found in the remote system"""

error_prefix = "Object not found"
error_default = "Object not found in remote system"


class ObjectExistsSyncException(BaseSyncException):
"""Exception when an object already exists in the remote system"""

error_prefix = "Object exists"
error_default = "Object exists in remote system"


class BadRequestSyncException(BaseSyncException):
"""Exception when invalid data was sent to the remote system"""

error_prefix = "Bad request"
error_default = "Bad request to remote system"


class DryRunRejected(BaseSyncException):
"""When dry_run is enabled and a provider dropped a mutating request"""
Expand Down
Loading