diff --git a/frontend-v2/src/features/login/login.tsx b/frontend-v2/src/features/login/login.tsx index 06edd9af..056c2373 100644 --- a/frontend-v2/src/features/login/login.tsx +++ b/frontend-v2/src/features/login/login.tsx @@ -38,9 +38,20 @@ const Login: React.FC = ({ onLogin, isLoading, errorMessage }) => {
- + + pkpd explorer + - Login + Login = 200 && response.status <= 299) { return response.json(); } else { - throw Error(response.statusText); + return response.json() + .then((data) => { + throw new ServerError(data.detail); + }) + .catch((err) => { + if (err instanceof ServerError) { + throw err; + } else { + throw Error(response.statusText); + } + }); } } @@ -80,7 +96,7 @@ export const login = createAsyncThunk< return { isAuthenticated: true, user: data.user }; }) .catch((err) => { - return rejectWithValue({ error: err.message }); + return rejectWithValue({ error: err.message}); }); return response; }, diff --git a/pkpdapp/pkpdapp/api/views/login.py b/pkpdapp/pkpdapp/api/views/login.py index 99e25299..8ac15309 100644 --- a/pkpdapp/pkpdapp/api/views/login.py +++ b/pkpdapp/pkpdapp/api/views/login.py @@ -39,7 +39,7 @@ def login_view(request): user = authenticate(username=username, password=password) if user is None: - return JsonResponse({'detail': 'Invalid credentials.'}, status=400) + return JsonResponse({'detail': 'Invalid credentials. Either you have supplied an incorrect username/password combination, or you do not have sufficient access'}, status=400) login(request, user)