From ff8a91599a24e51879c8152ba4464afe577076b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Bastian?= Date: Sun, 17 Apr 2022 18:30:38 +0200 Subject: [PATCH] Don't use abort for cleaner errors --- gitea_hooks/app.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gitea_hooks/app.py b/gitea_hooks/app.py index e68040f..fc9482c 100644 --- a/gitea_hooks/app.py +++ b/gitea_hooks/app.py @@ -3,7 +3,7 @@ import hmac import hashlib import json from collections import defaultdict -from flask import Flask, request, abort +from flask import Flask, request from .conf import Configuration config = Configuration() @@ -19,12 +19,12 @@ def webhook_receiver(hook_type): def inner(func): def wrapped(hook_name: str): if request.content_length is None or request.content_length > 32000: - abort(400) + return "Too much content", 400 if request.content_type != "application/json": return "Expected json", 415 if hook_name not in relevant_hooks: - abort(404) + return "No such hook", 404 hook_conf = relevant_hooks[hook_name] raw_payload: bytes = request.get_data(cache=False) @@ -33,7 +33,7 @@ def webhook_receiver(hook_type): hook_conf["secret"].encode("utf-8"), raw_payload, hashlib.sha256 ).hexdigest() if not hmac.compare_digest(provided_sig, computed_sig): - abort(403) + return "Bad credentials", 403 try: payload = json.loads(raw_payload)