浏览代码

add more check to new custom alias

Son NK 5 年之前
父节点
当前提交
d322d543af
共有 1 个文件被更改,包括 5 次插入2 次删除
  1. 5 2
      app/api/views/new_custom_alias.py

+ 5 - 2
app/api/views/new_custom_alias.py

@@ -40,8 +40,11 @@ def new_custom_alias():
     hostname = request.args.get("hostname")
 
     data = request.get_json()
-    alias_prefix = data["alias_prefix"]
-    alias_suffix = data["alias_suffix"]
+    if not data:
+        return jsonify(error="request body cannot be empty"), 400
+
+    alias_prefix = data.get("alias_prefix", "")
+    alias_suffix = data.get("alias_suffix", "")
 
     # make sure alias_prefix is not empty
     alias_prefix = alias_prefix.strip()