Skip to content

chore(site): migrate a few services to react-query used in the DashboardProvider #9667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Minor fixes
  • Loading branch information
BrunoQuaresma committed Sep 14, 2023
commit 16c08b8e243b03226777d7940bd2cfc9c5564811
6 changes: 4 additions & 2 deletions site/src/components/RequireAuth/RequireAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { embedRedirect } from "../../utils/redirect";
import { FullScreenLoader } from "../Loader/FullScreenLoader";
import { DashboardProvider } from "components/Dashboard/DashboardProvider";
import { ProxyProvider } from "contexts/ProxyContext";
import { isApiError } from "api/errors";

export const RequireAuth: FC = () => {
const [authState, authSend] = useAuth();
Expand All @@ -18,12 +19,13 @@ export const RequireAuth: FC = () => {
useEffect(() => {
const interceptorHandle = axios.interceptors.response.use(
(okResponse) => okResponse,
(error) => {
(error: unknown) => {
// 401 Unauthorized
// If we encountered an authentication error, then our token is probably
// invalid and we should update the auth state to reflect that.
if (error.response.status === 401) {
if (isApiError(error) && error.response.status === 401) {
authSend("SIGN_OUT");
return;
}

// Otherwise, pass the response through so that it can be displayed in the UI
Expand Down
6 changes: 5 additions & 1 deletion site/src/utils/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ export const getMetadataAsJSON = <T extends Record<string, any>>(
try {
return JSON.parse(rawContent as string);
} catch (ex) {
throw new Error(`Failed to parse ${property} metadata`);
// In development the metadata is always going to be empty throwing this
// error
if (process.env.NODE_ENV === "production") {
console.warn(`Failed to parse ${property} metadata`);
}
}
}
};