commit bb48b03bec653e247b238828f43188f3e8dd47b4
parent f952f892402cd14a9855f720fb28f7f6a72d44b2
Author: MTRNord <mtrnord1@gmail.com>
Date: Fri, 28 Apr 2023 23:45:53 +0200
fix: Make sure the correct error types are used
Diffstat:
2 files changed, 16 insertions(+), 13 deletions(-)
diff --git a/src/app/api/api.ts b/src/app/api/api.ts
@@ -48,19 +48,21 @@ const baseQuery: BaseQueryFn<string | FetchArgs,
return rawBaseQuery(baseUrl)(args, api, extraOptions);
};
+const baseQueryWithRetry = retry(
+ async (args: string | FetchArgs, api, extraOptions) => {
+ const result = await baseQuery(args, api, extraOptions);
+ if (result.error?.status === 429) {
+ const retryAfterMs = (result.error.data as IRateLimitError).retry_after_ms;
+ if (retryAfterMs) {
+ await new Promise((resolve) => setTimeout(resolve, retryAfterMs));
+ }
+ }
+ return result;
+ }, { maxRetries: 3 });
+
export const matrixApi = createApi({
reducerPath: 'matrixApi',
- baseQuery: retry(
- async (args: string | FetchArgs, api, extraOptions) => {
- const result = await baseQuery(args, api, extraOptions);
- if (result.error?.status === 429) {
- const retryAfterMs = (result.error.data as IRateLimitError).retry_after_ms;
- if (retryAfterMs) {
- await new Promise((resolve) => setTimeout(resolve, retryAfterMs));
- }
- }
- return result;
- }, { maxRetries: 3 }),
+ baseQuery: baseQueryWithRetry,
tagTypes: ['Login', 'Flows', "WellKnown"],
endpoints: (builder) => ({
getWellKnown: builder.query<IWellKnown, undefined>({
diff --git a/src/components/login/login.tsx b/src/components/login/login.tsx
@@ -5,12 +5,14 @@ import Button from '../button/button';
import Header from '../header/header';
import Input from '../input/basic/input';
import { Navigate } from 'react-router-dom';
+import { SerializedError } from '@reduxjs/toolkit';
+import { FetchBaseQueryError } from '@reduxjs/toolkit/dist/query';
export function Login() {
const [login, { isLoading: loginPending, isSuccess, error: loginErrorRaw }] = useDoLoginMutation();
const [triggerWellKnown] = useLazyGetWellKnownQuery();
const [triggerLoginFlows] = useLazyGetLoginFlowsQuery();
- const [loginError, setLoginError] = useState(loginErrorRaw);
+ const [loginError, setLoginError] = useState<FetchBaseQueryError | SerializedError | undefined>(loginErrorRaw);
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const dispatch = useAppDispatch();
@@ -52,7 +54,6 @@ export function Login() {
setLoginError({ status: "CUSTOM_ERROR", error: 'No password login flow found' });
}
}
- // TODO: We need to make sure that we do well-known before login
return (
<form className="flex flex-col rounded-md shadow p-4 bg-white gap-2 min-w-[30rem]" onSubmit={(e) => {
e.preventDefault();