spacemonkd commented on code in PR #10900: URL: https://github.com/apache/ozone/pull/10900#discussion_r3896080015
########## ozone-ui/packages/shared/src/components/ErrorBoundary/QueryErrorBoundary.tsx: ########## @@ -0,0 +1,86 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import React from 'react'; +import { QueryErrorResetBoundary } from '@tanstack/react-query'; +import { HttpError } from '../../data/fetchJson'; +import { NetworkErrorState, ServerErrorState } from '../ErrorState/ErrorState'; +import { ErrorBoundary } from './ErrorBoundary'; + +/** Arguments passed to a custom {@link QueryErrorBoundary} fallback. */ +export interface QueryErrorFallbackProps { + error: Error; + /** Reset the failed queries and clear the boundary (wired to Retry). */ + retry: () => void; +} + +export interface QueryErrorBoundaryProps { + children: React.ReactNode; + /** Override the default (network vs. 500) error page. */ + fallback?: (props: QueryErrorFallbackProps) => React.ReactNode; + /** Reset the boundary when any of these values change (e.g. the route). */ + resetKeys?: unknown[]; +} + +/** + * The default fallback: a server-side failure (HTTP 5xx) shows the 500 state; + * anything else — a network/timeout failure (native `fetch` rejects with a + * `TypeError`), an aborted request, or an unclassified error — shows the network + * state. Both wire their action button to `retry`. + */ +function defaultFallback({ error, retry }: QueryErrorFallbackProps): React.ReactNode { + if (error instanceof HttpError && error.status >= 500) { + return <ServerErrorState onAction={retry} />; + } + return <NetworkErrorState onAction={retry} />; Review Comment: Ideally it should, I didn't have a proper artwork for the 4xx type errors. This is still being worked on so it has been unified under the network error. Since this is a feature branch we can improve these as I have the updated designs created. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
