Skip to content

Commit

Permalink
add new layer of error catching for sentry app base endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
Christinarlong committed Jan 6, 2025
1 parent a6680b4 commit 75bfa35
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/sentry/sentry_apps/api/bases/sentryapps.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ def wrapped(self, *args, **kwargs):
return wrapped


def _handle_sentry_app_exception(exception: Exception):
# If the error_type attr exists we know the error is one of SentryAppError or SentryAppIntegratorError
if hasattr(exception, "error_type"):
response = Response({"error": str(exception)}, status=exception.status_code)
response.exception = True
return response

# If not an audited sentry app error then default to using default error handler
return None


def ensure_scoped_permission(request: Request, allowed_scopes: Sequence[str] | None) -> bool:
"""
Verifies the User making the request has at least one required scope for
Expand Down Expand Up @@ -188,6 +199,11 @@ def convert_args(self, request: Request, *args, **kwargs):

return (args, kwargs)

def handle_exception_with_details(self, request, exc, handler_context=None, scope=None):
return _handle_sentry_app_exception(exception=exc) or super().handle_exception_with_details(
request, exc, handler_context, scope
)


class SentryAppPermission(SentryPermission):
unpublished_scope_map = {
Expand Down Expand Up @@ -273,6 +289,11 @@ def convert_args(
kwargs["sentry_app"] = sentry_app
return (args, kwargs)

def handle_exception_with_details(self, request, exc, handler_context=None, scope=None):
return _handle_sentry_app_exception(exception=exc) or super().handle_exception_with_details(
request, exc, handler_context, scope
)


class RegionSentryAppBaseEndpoint(IntegrationPlatformEndpoint):
def convert_args(
Expand All @@ -292,6 +313,11 @@ def convert_args(
kwargs["sentry_app"] = sentry_app
return (args, kwargs)

def handle_exception_with_details(self, request, exc, handler_context=None, scope=None):
return _handle_sentry_app_exception(exception=exc) or super().handle_exception_with_details(
request, exc, handler_context, scope
)


class SentryAppInstallationsPermission(SentryPermission):
scope_map = {
Expand Down Expand Up @@ -345,6 +371,11 @@ def convert_args(self, request: Request, organization_id_or_slug, *args, **kwarg
kwargs["organization"] = organization
return (args, kwargs)

def handle_exception_with_details(self, request, exc, handler_context=None, scope=None):
return _handle_sentry_app_exception(exception=exc) or super().handle_exception_with_details(
request, exc, handler_context, scope
)


class SentryAppInstallationPermission(SentryPermission):
scope_map = {
Expand Down Expand Up @@ -417,6 +448,11 @@ def convert_args(self, request: Request, uuid, *args, **kwargs):
kwargs["installation"] = installation
return (args, kwargs)

def handle_exception_with_details(self, request, exc, handler_context=None, scope=None):
return _handle_sentry_app_exception(exception=exc) or super().handle_exception_with_details(
request, exc, handler_context, scope
)


class SentryAppInstallationExternalIssuePermission(SentryAppInstallationPermission):
scope_map = {
Expand Down

0 comments on commit 75bfa35

Please sign in to comment.