clean up some code
This commit is contained in:
parent
8ff5f15467
commit
97fe1e8d68
2 changed files with 11 additions and 17 deletions
26
app.py
26
app.py
|
@ -33,6 +33,12 @@ def get_console_id(txt):
|
||||||
|
|
||||||
return "0"
|
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
|
# docker
|
||||||
if config["docker"]:
|
if config["docker"]:
|
||||||
report_dir = "/data/reports"
|
report_dir = "/data/reports"
|
||||||
|
@ -149,25 +155,13 @@ def syscheck():
|
||||||
@app.errorhandler(502)
|
@app.errorhandler(502)
|
||||||
def errorhandler(e):
|
def errorhandler(e):
|
||||||
if e.code == 400:
|
if e.code == 400:
|
||||||
jsonstring = {"message": "Bad Request.", "code": 400, "error": True}
|
return return_error("Bad request", 400), 400
|
||||||
resp = flask.Response(json.dumps(jsonstring))
|
|
||||||
resp.headers["Content-Type"] = "application/json"
|
|
||||||
return resp, 400
|
|
||||||
elif e.code == 404:
|
elif e.code == 404:
|
||||||
jsonstring = {"message": "Not found.", "code": 404, "error": True}
|
return return_error("Not found", 404), 404
|
||||||
resp = flask.Response(json.dumps(jsonstring))
|
|
||||||
resp.headers["Content-Type"] = "application/json"
|
|
||||||
return resp, 404
|
|
||||||
elif e.code == 405:
|
elif e.code == 405:
|
||||||
jsonstring = {"message": "Method not allowed.", "code": 405, "error": True}
|
return return_error("Method not allowed", 405), 405
|
||||||
resp = flask.Response(json.dumps(jsonstring))
|
|
||||||
resp.headers["Content-Type"] = "application/json"
|
|
||||||
return resp, 405
|
|
||||||
elif e.code == 502:
|
elif e.code == 502:
|
||||||
jsonstring = {"message": "Bad Gateway.", "code": 502, "error": True}
|
return return_error("Bad gateway", 502), 502
|
||||||
resp = flask.Response(json.dumps(jsonstring))
|
|
||||||
resp.headers["Content-Type"] = "application/json"
|
|
||||||
return resp, 502
|
|
||||||
|
|
||||||
|
|
||||||
# run server
|
# run server
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"ip": "0.0.0.0",
|
"ip": "0.0.0.0",
|
||||||
"port": "6969",
|
"port": "6969",
|
||||||
"version": "1.0.9",
|
"version": "1.0.10",
|
||||||
"upload_passwords": [
|
"upload_passwords": [
|
||||||
"d2wRuTEObSAN",
|
"d2wRuTEObSAN",
|
||||||
"B277eNGp789a"
|
"B277eNGp789a"
|
||||||
|
|
Loading…
Add table
Reference in a new issue