From d3fe363776fb1a892c2d647a2b858d2382d09293 Mon Sep 17 00:00:00 2001 From: 2000-Trek Date: Wed, 21 Jun 2023 21:33:23 +0200 Subject: [PATCH] Error codes website + Doc --- main.py | 45 +++++++++++++----------------------- templates/documentation.html | 9 +++++--- 2 files changed, 22 insertions(+), 32 deletions(-) diff --git a/main.py b/main.py index 5ff5bf8..113305f 100644 --- a/main.py +++ b/main.py @@ -89,7 +89,7 @@ def user_info(): """ else: - return "User does not exists" + return "Error: 043" @app.route("/adduser") def new_user(): @@ -121,7 +121,7 @@ def adduser(): socketio.emit("update", "update") return 'Added user user and tag list

The creator of this website accepts no liability for any linguistic or technical errors!

' else: - return '

User already exists

user and tag list' + return '

Error: 170

user and tag list' @app.route("/change", methods=['GET']) @@ -130,7 +130,7 @@ def change(): try: change = int(request.args.get("change")) except ValueError: - return '

Please enter a number!

tags and user list' + return '

Error: 095

tags and user list' c.execute(f"UPDATE users SET balance = balance + {change} WHERE id={user_id}") socketio.emit("update", "update") return """ @@ -160,7 +160,7 @@ def get_addtag_request(): try: user_id = int(request.args.get("id")) except: #except im Normalen Code! - return "Wrong user id!" + return "Error: 095" session_id = uuid.uuid4() session[id] = session_id users.put([user_id, "add", session_id]) @@ -180,21 +180,17 @@ def request_addtag(data): time.sleep(1) i += 1 if i > 20: - socketio.emit("error", "timeout", to=session[id]) + socketio.emit("error", "352", to=session[id]) notimportant = users.get() break else: finished = None - c.execute(f"SELECT * FROM users WHERE id ={user[0]}") - username = c.fetchall()[0][1] - if message == "Error: 170": - socketio.emit("finished", f"{message}") - else: - socketio.emit("finished", f"Added {message} to {username}", to=session[id]) + socketio.emit("finished", f"{message}", to=session[id]) + else: socketio.emit("busy", "busy", to=session[id]) else: - socketio.emit("error", "error", to=session[id]) + socketio.emit("error", "418", to=session[id]) leave_room(session[id]) @app.route("/removetag", methods=['GET']) @@ -224,21 +220,16 @@ def request_removetag(data): time.sleep(1) i += 1 if i > 20: - socketio.emit("error", "timeout", to=session[id]) + socketio.emit("error", "352", to=session[id]) notimportant = users.get() break else: finished = None - c.execute(f"SELECT * FROM users WHERE id ={user}") - username = c.fetchall()[0][1] - if message == "Tag does not exist": - socketio.emit("finished", f"{message}") - else: - socketio.emit("finished", f"removed {message} from {username}") + socketio.emit("finished", f"{message}", to=session[id]) else: socketio.emit("busy", "busy", to=session[id]) else: - socketio.emit("error", "error", to=session[id]) + socketio.emit("error", "418", to=session[id]) leave_room(session[id]) #api @@ -254,30 +245,26 @@ def get_id(): queue_item = users.get() user = queue_item[0] state = queue_item[1] + c.execute(f"SELECT * FROM users WHERE id={user}") + username = c.fetchall()[0][1] if state == "add": c.execute(f"SELECT * FROM tags WHERE tagid={tag_id}") if c.fetchall() != []: - message = "Tag already exists" + message = "Error: 170" finished = queue_item return make_response(json.dumps({"mode":"0","error":"170"})) else: c.execute(f"INSERT OR IGNORE INTO tags (tagid, userid) VALUES ({tag_id}, {user})") - message = tag_id + message = f"Added {tag_id} to {username}" finished = queue_item - c.execute(f"SELECT * FROM users WHERE id={user}") - username = c.fetchall()[0][1] - conn.commit() return make_response(json.dumps({"mode":"2","username":username,"code":"1"})) elif state == "remove": c.execute(f"SELECT * FROM tags WHERE (tagid = {tag_id} AND userid = {user})") tags = c.fetchall() if tags != []: c.execute(f"DELETE FROM tags WHERE (tagid = {tag_id} AND userid = {user}) ") - message = tag_id + message = f"Removed {tag_id} from {username}" finished = queue_item - c.execute(f"SELECT * FROM users WHERE id={user}") - username = c.fetchall()[0][1] - conn.commit() return make_response(json.dumps({"mode":"2","username":username,"code":"2"})) else: message = "Tag does not exist" diff --git a/templates/documentation.html b/templates/documentation.html index fc90267..0a7f9c3 100644 --- a/templates/documentation.html +++ b/templates/documentation.html @@ -14,10 +14,13 @@

 

API:

-

API Documentation:

-

Error Codes:

-

Error Codes Documentation

+

170: Tag already exists

+

054: Tag does not exists

+

757: Usere already exists

+

043: User does not exists

+

352: Timeout

+

095: Input is not a Number