Skip to content

Commit 8b4cba2

Browse files
authored
feat(errors): introduce AuthenticationError and update failure classification (#274)
1 parent 1612a1e commit 8b4cba2

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

core/errors.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
from enum import Enum
1212

1313

14+
class AuthenticationError(RuntimeError):
15+
"""Raised when collector credentials are rejected (HTTP 401/403 or equivalent)."""
16+
17+
1418
class CollectorFailureCategory(str, Enum):
1519
"""High-level failure bucket for collector runs."""
1620

@@ -183,6 +187,8 @@ def classify_failure(exc: BaseException) -> CollectorFailureCategory:
183187
return CollectorFailureCategory.COMMAND
184188
if ValidationError and isinstance(exc, ValidationError):
185189
return CollectorFailureCategory.VALIDATION
190+
if isinstance(exc, AuthenticationError):
191+
return CollectorFailureCategory.AUTH
186192

187193
try:
188194
from django.db import Error as DjangoDBError

core/tests/test_errors.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from django.core.management.base import CommandError
1111

1212
from core.errors import (
13+
AuthenticationError,
1314
CollectorFailureCategory,
1415
_classify_os_error,
1516
classify_failure,
@@ -58,6 +59,13 @@ def test_classify_command_error():
5859
assert classify_failure(CommandError("bad")) is CollectorFailureCategory.COMMAND
5960

6061

62+
def test_classify_authentication_error():
63+
assert (
64+
classify_failure(AuthenticationError("bad creds"))
65+
is CollectorFailureCategory.AUTH
66+
)
67+
68+
6169
def test_classify_django_db_error_unknown():
6270
from django.db import OperationalError
6371

0 commit comments

Comments
 (0)