From 97fe1e8d6872f654b46c826976b446949ddf1e0b Mon Sep 17 00:00:00 2001 From: CrafterPika Date: Tue, 5 Nov 2024 18:56:29 +0100 Subject: [PATCH] clean up some code --- app.py | 26 ++++++++++---------------- config.json | 2 +- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/app.py b/app.py index 39b7d17..e733325 100644 --- a/app.py +++ b/app.py @@ -33,6 +33,12 @@ def get_console_id(txt): return "0" +def return_error(message: string, code: int): + jsonstring = {"message": message, "code": code, "error": True} + resp = flask.Response(json.dumps(jsonstring)) + resp.headers["Content-Type"] = "application/json" + return resp + # docker if config["docker"]: report_dir = "/data/reports" @@ -149,25 +155,13 @@ def syscheck(): @app.errorhandler(502) def errorhandler(e): if e.code == 400: - jsonstring = {"message": "Bad Request.", "code": 400, "error": True} - resp = flask.Response(json.dumps(jsonstring)) - resp.headers["Content-Type"] = "application/json" - return resp, 400 + return return_error("Bad request", 400), 400 elif e.code == 404: - jsonstring = {"message": "Not found.", "code": 404, "error": True} - resp = flask.Response(json.dumps(jsonstring)) - resp.headers["Content-Type"] = "application/json" - return resp, 404 + return return_error("Not found", 404), 404 elif e.code == 405: - jsonstring = {"message": "Method not allowed.", "code": 405, "error": True} - resp = flask.Response(json.dumps(jsonstring)) - resp.headers["Content-Type"] = "application/json" - return resp, 405 + return return_error("Method not allowed", 405), 405 elif e.code == 502: - jsonstring = {"message": "Bad Gateway.", "code": 502, "error": True} - resp = flask.Response(json.dumps(jsonstring)) - resp.headers["Content-Type"] = "application/json" - return resp, 502 + return return_error("Bad gateway", 502), 502 # run server diff --git a/config.json b/config.json index 91429e4..8b5728b 100644 --- a/config.json +++ b/config.json @@ -1,7 +1,7 @@ { "ip": "0.0.0.0", "port": "6969", - "version": "1.0.9", + "version": "1.0.10", "upload_passwords": [ "d2wRuTEObSAN", "B277eNGp789a"