浏览代码

Add human-readable error messages for API error responses

Tulir Asokan 4 年之前
父节点
当前提交
6b5faf49e5
共有 1 个文件被更改,包括 6 次插入2 次删除
  1. 6 2
      mautrix_instagram/web/provisioning_api.py

+ 6 - 2
mautrix_instagram/web/provisioning_api.py

@@ -132,10 +132,12 @@ class ProvisioningAPI:
                 "response": e.body.serialize(),
             }, status=202, headers=self._acao_headers)
         except IGLoginInvalidUserError:
-            return web.json_response(data={"status": "invalid-username"},
+            return web.json_response(data={"error": "Invalid username",
+                                           "status": "invalid-username"},
                                      status=404, headers=self._acao_headers)
         except IGLoginBadPasswordError:
-            return web.json_response(data={"status": "incorrect-password"},
+            return web.json_response(data={"error": "Incorrect password",
+                                           "status": "incorrect-password"},
                                      status=403, headers=self._acao_headers)
         return await self._finish_login(user, state, resp.logged_in_user)
 
@@ -170,6 +172,7 @@ class ProvisioningAPI:
                                               is_totp=is_totp)
         except IGBad2FACodeError:
             return web.json_response(data={
+                "error": "Incorrect 2-factor authentication code",
                 "status": "incorrect-2fa-code",
             }, status=403, headers=self._acao_headers)
         except IGCheckpointError as e:
@@ -194,6 +197,7 @@ class ProvisioningAPI:
             resp = await api.challenge_send_security_code(code=code)
         except IGChallengeWrongCodeError:
             return web.json_response(data={
+                "error": "Incorrect challenge code",
                 "status": "incorrect-challenge-code",
             }, status=403, headers=self._acao_headers)
         return await self._finish_login(user, state, resp.logged_in_user)