fix(exception): 优化异常错误处理

This commit is contained in:
sophie committed 2026-06-02 10:32:44 +08:00
1 parent 2a036764e3
commit 14c5903aef
3 files changed
+24 -6

No files matched your search

+7 -3
View File
@@ -100,8 +100,12 @@ def test_login_success(client):
def test_login_fail(client):
res = client.post('/api/user/login', json={'username': 'test1', 'password': 'wrongpassword'})
assert res.status_code == 401
assert 'Incorrect password' in res.get_json()['error']
body = res.get_json()
assert body['error']['code'] == 'AUTH.INCORRECT_PASSWORD'
assert 'Incorrect password' in body['error']['message']
res = client.post('/api/user/login', json={'username': 'nonexistent', 'password': 'password'})
assert res.status_code == 404
assert 'User not found' in res.get_json()['error']
body = res.get_json()
assert body['error']['code'] == 'AUTH.USER_NOT_FOUND'
assert 'User not found' in body['error']['message']