mirror of
https://github.com/Llloooggg/TextSouls.git
synced 2026-03-06 20:46:23 +03:00
backend + telegram: добавлена обработка ошибок при регистрации
This commit is contained in:
@@ -9,7 +9,13 @@ class Backend:
|
||||
base_url = config_data["backend_settings"]["base_url"]
|
||||
|
||||
def post(self, relative_url, data):
|
||||
requests.post(f"{self.base_url}{relative_url}", json=data)
|
||||
try:
|
||||
response = requests.post(
|
||||
f"{self.base_url}{relative_url}", json=data
|
||||
)
|
||||
return {"error": None, "response": response}
|
||||
except Exception as err:
|
||||
return {"error": err}
|
||||
|
||||
|
||||
backend = Backend()
|
||||
|
||||
@@ -22,8 +22,15 @@ async def start(message):
|
||||
"last_name": tg_user.last_name,
|
||||
"username": tg_user.username,
|
||||
}
|
||||
backend.post("/registration", ts_user)
|
||||
await message.reply("Nice!")
|
||||
result = backend.post("/registration", ts_user)
|
||||
if not result["error"] and result["response"].ok:
|
||||
data = json.loads(result["response"].text)
|
||||
if data["created"]:
|
||||
await message.reply("Добро пожаловать!")
|
||||
else:
|
||||
await message.reply("Добро пожаловать! Снова")
|
||||
else:
|
||||
await message.reply("Упс! Что-то пошло не так")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user