From 3da71f4c91b43930e22c225c95b282ff2507a32d Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Thu, 10 Apr 2025 16:05:25 -0600 Subject: [PATCH] =?UTF-8?q?teat=20pot=20error=20update=20=F0=9F=AB=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/api/buster_rest/errors.ts | 16 ++- .../api/buster_rest/metrics/queryRequests.ts | 30 ++-- web/src/api/buster_rest/metrics/requests.ts | 6 +- .../ShareMenu/ShareMenuContentPublish.tsx | 1 - .../context/Assets/BusterAssetsProvider.tsx | 53 ++++++- web/src/controllers/AppPasswordAccess.tsx | 18 ++- .../AppAssetCheckLayout.tsx | 134 +++--------------- .../AppAssetLoadingContainer.tsx | 107 -------------- .../AppAssetCheckLayout/useGetAsset.tsx | 129 +++++++++++++++++ 9 files changed, 241 insertions(+), 253 deletions(-) delete mode 100644 web/src/layouts/AppAssetCheckLayout/AppAssetLoadingContainer.tsx create mode 100644 web/src/layouts/AppAssetCheckLayout/useGetAsset.tsx diff --git a/web/src/api/buster_rest/errors.ts b/web/src/api/buster_rest/errors.ts index 6de4c4078..355c88698 100644 --- a/web/src/api/buster_rest/errors.ts +++ b/web/src/api/buster_rest/errors.ts @@ -1,32 +1,34 @@ +import { AxiosError } from 'axios'; import isString from 'lodash/isString'; export const rustErrorHandler = (errors: any = {}): RustApiError => { const data = errors?.response?.data; + const status = errors?.status; if (data && isString(data)) { - return { message: String(data) }; + return { message: String(data), status }; } if (data && data?.message) { - return { message: String(data.message) }; + return { message: String(data.message), status }; } if (data && data?.detail) { if (typeof data.detail === 'string') { - return { message: String(data.detail) }; + return { message: String(data.detail), status }; } if (data.detail?.[0]) { - return { message: String(data.detail[0].msg) }; + return { message: String(data.detail[0].msg), status }; } - return { message: String(data.detail) }; + return { message: String(data.detail), status }; } if (errors?.message) { - return { message: String(errors.message) }; + return { message: String(errors.message), status }; } if (typeof errors === 'string') { - return { message: String(errors) }; + return { message: String(errors), status }; } return {}; diff --git a/web/src/api/buster_rest/metrics/queryRequests.ts b/web/src/api/buster_rest/metrics/queryRequests.ts index 4932ef632..621b45190 100644 --- a/web/src/api/buster_rest/metrics/queryRequests.ts +++ b/web/src/api/buster_rest/metrics/queryRequests.ts @@ -21,7 +21,7 @@ import { collectionQueryKeys } from '@/api/query_keys/collection'; import { useMemo } from 'react'; import { useBusterAssetsContextSelector } from '@/context/Assets/BusterAssetsProvider'; import { useGetUserFavorites } from '../users'; -import type { IBusterMetric } from '@/api/asset_interfaces/metric'; +import type { BusterMetricData, IBusterMetric } from '@/api/asset_interfaces/metric'; import { create } from 'mutative'; import { useAddAssetToCollection, @@ -81,7 +81,7 @@ export const useGetMetric = ( return useQuery({ ...options, queryFn, - enabled: !!id, + enabled: false, //In the year of our lord 2025, April 10, I, Nate Kelley, decided to disable this query in favor of explicityly fetching the data. May god have mercy on our souls. retry(failureCount, error) { if (error?.message !== undefined) { setAssetPasswordError(id!, error.message || 'An error occurred'); @@ -112,13 +112,19 @@ export const useGetMetricsList = ( /** * This is a hook that will use the version number from the URL params if it exists. */ -export const useGetMetricData = ({ - id, - versionNumber: versionNumberProp -}: { - id: string | undefined; - versionNumber?: number; -}) => { +export const useGetMetricData = ( + { + id, + versionNumber: versionNumberProp + }: { + id: string | undefined; + versionNumber?: number; + }, + params?: Omit, 'queryKey' | 'queryFn'> +) => { + const getAssetPassword = useBusterAssetsContextSelector((x) => x.getAssetPassword); + const { password } = getAssetPassword(id!); + const { isFetched: isFetchedMetric, error: errorMetric, @@ -141,7 +147,7 @@ export const useGetMetricData = ({ }, [versionNumberProp, versionNumberFromParams]); const queryFn = useMemoizedFn(() => { - return getMetricData({ id: id!, version_number: versionNumber }); + return getMetricData({ id: id!, version_number: versionNumber, password }); }); return useQuery({ @@ -149,7 +155,9 @@ export const useGetMetricData = ({ queryFn, enabled: () => { return !!id && isFetchedMetric && !errorMetric && !!fetchedMetricData; - } + }, + select: params?.select, + ...params }); }; diff --git a/web/src/api/buster_rest/metrics/requests.ts b/web/src/api/buster_rest/metrics/requests.ts index f96d90363..109225765 100644 --- a/web/src/api/buster_rest/metrics/requests.ts +++ b/web/src/api/buster_rest/metrics/requests.ts @@ -37,13 +37,15 @@ export const getMetric_server = async ({ id, password }: Parameters { return mainApi - .get(`/metrics/${id}/data`, { params: { version_number } }) + .get(`/metrics/${id}/data`, { params: { password, version_number } }) .then((res) => res.data); }; diff --git a/web/src/components/features/ShareMenu/ShareMenuContentPublish.tsx b/web/src/components/features/ShareMenu/ShareMenuContentPublish.tsx index 1e410c206..2c409e380 100644 --- a/web/src/components/features/ShareMenu/ShareMenuContentPublish.tsx +++ b/web/src/components/features/ShareMenu/ShareMenuContentPublish.tsx @@ -166,7 +166,6 @@ export const ShareMenuContentPublish: React.FC = Reac