Nenne in der Paperless-Fehlermeldung Statuscode, Pfad und Grund, damit sich eine abgelehnte Abfrage zuordnen lässt.
Deploy Development / deploy (push) Successful in 50s
Test Suite / pytest-backend (push) Failing after 7s
Test Suite / smoke-dev (push) Successful in 0s
Test Suite / frontend-build (push) Successful in 26s

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
StommerandClaude Sonnet 5.5 committed 2026-10-24 22:53:46 +02:00
1 parent 38406d3293
commit 0f2b7a8fab
2 files changed
+43 -1

No files matched your search

+12 -1
View File
@@ -1014,11 +1014,22 @@ def _paperless_get(base: str, token: str, path: str, params: dict) -> dict:
except HTTPError as exc: except HTTPError as exc:
if exc.code in {401, 403}: if exc.code in {401, 403}:
raise unprocessable("Paperless hat den Schlüssel abgelehnt.") from exc raise unprocessable("Paperless hat den Schlüssel abgelehnt.") from exc
raise unprocessable("Paperless hat die Anfrage nicht beantwortet.") from exc raise unprocessable(f"Paperless hat die Anfrage nicht beantwortet ({_refusal(exc, path)}).") from exc
except (URLError, TimeoutError, json.JSONDecodeError) as exc: except (URLError, TimeoutError, json.JSONDecodeError) as exc:
raise unprocessable("Paperless ist nicht erreichbar.") from exc raise unprocessable("Paperless ist nicht erreichbar.") from exc
def _refusal(exc: HTTPError, path: str) -> str:
"""Status and, when Paperless names one, its reason. The body is the owner's own instance, cut short."""
reason = ""
try:
body = json.loads(exc.read(2000).decode("utf-8", "replace"))
reason = json.dumps(body, ensure_ascii=False)[:240] if isinstance(body, (dict, list)) else ""
except (ValueError, OSError):
reason = ""
return f"HTTP {exc.code} auf {path}" + (f": {reason}" if reason else "")
def _correspondent(doc: dict, names: dict | None = None) -> str | None: def _correspondent(doc: dict, names: dict | None = None) -> str | None:
value = doc.get("correspondent_name") or doc.get("correspondent") value = doc.get("correspondent_name") or doc.get("correspondent")
if isinstance(value, str) and value.strip(): if isinstance(value, str) and value.strip():
+31
View File
@@ -10,6 +10,8 @@ import io
import zipfile import zipfile
from email.parser import BytesParser from email.parser import BytesParser
import pytest
from app.media.port import MemoryAdapter from app.media.port import MemoryAdapter
from app.sourceaccess import borrow_original, complete_borrow from app.sourceaccess import borrow_original, complete_borrow
from app.sourceregistry import SourceModule, unregister_source, register_source from app.sourceregistry import SourceModule, unregister_source, register_source
@@ -652,6 +654,35 @@ def test_paperless_custom_field_filters_use_the_instance_fields(client, db, monk
) )
def test_paperless_refusal_names_the_status_and_reason(monkeypatch):
import io
from urllib.error import HTTPError
import app.sources as sources
from app.core.errors import Problem
def refuse(code, body):
def fake(request, timeout=0):
raise HTTPError(request.full_url, code, "x", {}, io.BytesIO(body))
return fake
monkeypatch.setattr(sources, "urlopen", refuse(400, '{"custom_field_query": ["Ungültig"]}'.encode()))
with pytest.raises(Problem) as caught:
sources._paperless_get("https://paper.example.test", "token-alpha", "/api/documents/", {"page_size": "20"})
assert "HTTP 400 auf /api/documents/" in caught.value.detail
assert "custom_field_query" in caught.value.detail
assert "token-alpha" not in caught.value.detail
monkeypatch.setattr(sources, "urlopen", refuse(500, b"<html>Fehler</html>"))
with pytest.raises(Problem) as caught:
sources._paperless_get("https://paper.example.test", "token-alpha", "/api/documents/", {})
assert caught.value.detail.endswith("(HTTP 500 auf /api/documents/).")
monkeypatch.setattr(sources, "urlopen", refuse(403, b"{}"))
with pytest.raises(Problem) as caught:
sources._paperless_get("https://paper.example.test", "token-alpha", "/api/documents/", {})
assert "Schlüssel abgelehnt" in caught.value.detail
def test_paperless_thumbnail_is_bound_to_the_owners_instance(client, db, monkeypatch): def test_paperless_thumbnail_is_bound_to_the_owners_instance(client, db, monkeypatch):
import app.sources as sources import app.sources as sources