diff options
| author | Dennis Fink | 2026-11-14 19:43:28 +0100 |
|---|---|---|
| committer | Dennis Fink | 2026-11-14 19:43:28 +0100 |
| commit | c74feda222745ab7cca8993df83d9ea5f9d07e5b (patch) | |
| tree | acc7bf9bd7223f9d685d6c2954c5c90d7a9e36f0 /webmentions_ssg | |
| parent | e52e554e2d033dd5ef8397617644e90e354f9560 (diff) | |
| download | webmentions-ssg-c74feda222745ab7cca8993df83d9ea5f9d07e5b.tar.gz webmentions-ssg-c74feda222745ab7cca8993df83d9ea5f9d07e5b.zip | |
refactor(core): use HTTPStatus consistently
Replace numeric HTTP response and assertion codes in views and tests
with `HTTPStatus` members so status handling is more descriptive and
consistent.
Diffstat (limited to 'webmentions_ssg')
| -rw-r--r-- | webmentions_ssg/views/admin.py | 11 | ||||
| -rw-r--r-- | webmentions_ssg/views/endpoint.py | 7 |
2 files changed, 10 insertions, 8 deletions
diff --git a/webmentions_ssg/views/admin.py b/webmentions_ssg/views/admin.py index 1025e69..2ccd92a 100644 --- a/webmentions_ssg/views/admin.py +++ b/webmentions_ssg/views/admin.py @@ -5,6 +5,7 @@ """Authenticated incoming and outgoing Webmention management.""" import uuid +from http import HTTPStatus import sqlalchemy as sa from flask import abort, flash, redirect, render_template, request, url_for @@ -50,7 +51,7 @@ def delete_received_webmention(identifier: uuid.UUID) -> ResponseReturnValue: :returns: Redirect response to the received Webmentions view. """ if not forms.AdminActionForm().validate_on_submit(): - abort(400) + abort(HTTPStatus.BAD_REQUEST) webmention = db.get_or_404(ReceivedWebmention, identifier) @@ -75,7 +76,7 @@ def reverify_received_webmention(identifier: uuid.UUID) -> ResponseReturnValue: :returns: Redirect response to the received Webmentions view. """ if not forms.AdminActionForm().validate_on_submit(): - abort(400) + abort(HTTPStatus.BAD_REQUEST) webmention = db.get_or_404(ReceivedWebmention, identifier) @@ -121,7 +122,7 @@ def rescan_sent_sources() -> ResponseReturnValue: :returns: Redirect response to the sent Webmentions view. """ if not forms.AdminActionForm().validate_on_submit(): - abort(400) + abort(HTTPStatus.BAD_REQUEST) manual_scan_sources() flash("Source rescan queued.", "success") @@ -172,12 +173,12 @@ def resend_sent_webmention( :returns: Redirect response to the source details view. """ if not forms.AdminActionForm().validate_on_submit(): - abort(400) + abort(HTTPStatus.BAD_REQUEST) webmention = db.get_or_404(SentWebmention, webmention_identifier) if webmention.source_id != source_identifier: - abort(404) + abort(HTTPStatus.NOT_FOUND) # Requeue the existing desired revision instead of inventing a new source # revision. send_webmention() otherwise exits when this revision has already diff --git a/webmentions_ssg/views/endpoint.py b/webmentions_ssg/views/endpoint.py index 85ec398..06740e5 100644 --- a/webmentions_ssg/views/endpoint.py +++ b/webmentions_ssg/views/endpoint.py @@ -6,6 +6,7 @@ import uuid from datetime import UTC, datetime, timedelta +from http import HTTPStatus from typing import cast import sqlalchemy as sa @@ -141,7 +142,7 @@ def endpoint() -> ResponseReturnValue: form = forms.EndpointForm(meta={"csrf": False}) if not form.validate_on_submit(): - return form.errors, 400 + return form.errors, HTTPStatus.BAD_REQUEST source = cast(str, form.source.data) target = cast(str, form.target.data) @@ -149,7 +150,7 @@ def endpoint() -> ResponseReturnValue: result = submit_received(source, target) if result is None: - return {"error": "Webmention URL fingerprint conflict"}, 409 + return {"error": "Webmention URL fingerprint conflict"}, HTTPStatus.CONFLICT identifier, should_verify = result @@ -158,7 +159,7 @@ def endpoint() -> ResponseReturnValue: status_url = url_for("root.status", identifier=str(identifier), _external=True) - return Response(status=201, headers={"Location": status_url}) + return Response(status=HTTPStatus.CREATED, headers={"Location": status_url}) @root_page.route("/status/<uuid:identifier>") |
