Skip to content

Commit 7486060

Browse files
committed
Current state
Signed-off-by: brookewp <[email protected]>
1 parent 23c9de0 commit 7486060

File tree

4 files changed

+17
-14
lines changed

4 files changed

+17
-14
lines changed

example/rest-api/art-institute/art-institute.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function register_aic_block(): void {
2121
'service_config' => [
2222
'__version' => 1,
2323
'display_name' => 'Art Institute of Chicago',
24-
'endpoint' => 'https://api.artic.edu/api/v1/artworks',
24+
'endpoint' => 'https://api.artic.edu/api!/v1/artworks',
2525
'request_headers' => [
2626
'Content-Type' => 'application/json',
2727
],

remote-data-blocks.php

+1
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@
5555
// Plugin developers: If you need to register additional code for testing, you
5656
// can do so here, e.g.:
5757
// require_once __DIR__ . '/example/shopify/register.php';
58+
require_once __DIR__ . '/example/rest-api/art-institute/art-institute.php';

src/blocks/remote-data-container/edit.tsx

+15-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { DataPanel } from '@/blocks/remote-data-container/components/panels/Data
88
import { OverridesPanel } from '@/blocks/remote-data-container/components/panels/OverridesPanel';
99
import { PatternSelection } from '@/blocks/remote-data-container/components/pattern-selection/PatternSelection';
1010
import { Placeholder } from '@/blocks/remote-data-container/components/placeholders/Placeholder';
11+
import { PlaceholderError } from '@/blocks/remote-data-container/components/placeholders/PlaceholderError';
1112
import {
1213
CONTAINER_CLASS_NAME,
1314
DISPLAY_QUERY_KEY,
@@ -39,13 +40,18 @@ export function Edit( props: BlockEditProps< RemoteDataBlockAttributes > ) {
3940
resetInnerBlocks,
4041
} = usePatterns( blockName, rootClientId );
4142

42-
const { data, fetch, loading, reset } = useRemoteData( {
43+
const { data, error, fetch, loading, reset } = useRemoteData( {
4344
blockName,
4445
externallyManagedRemoteData: remoteDataAttribute,
4546
externallyManagedUpdateRemoteData: updateRemoteData,
47+
// error is passed along with this query key
48+
// queryKey: 'RemoteDataBlocks\\Config\\Query\\HttpQuery',
49+
// error is undefined with this query key
4650
queryKey: DISPLAY_QUERY_KEY,
4751
} );
4852

53+
console.log( 'error', error );
54+
4955
const [ showPatternSelection, setShowPatternSelection ] = useState< boolean >( false );
5056

5157
function refreshRemoteData(): void {
@@ -83,6 +89,14 @@ export function Edit( props: BlockEditProps< RemoteDataBlockAttributes > ) {
8389
}
8490
}
8591

92+
if ( error ) {
93+
return (
94+
<div { ...blockProps }>
95+
<PlaceholderError blockName={ blockConfig.settings.title } error={ error } />
96+
</div>
97+
);
98+
}
99+
86100
// No remote data has been selected yet, show a placeholder.
87101
if ( ! data ) {
88102
return (

src/blocks/remote-data-container/hooks/useRemoteData.ts

-12
Original file line numberDiff line numberDiff line change
@@ -199,18 +199,6 @@ export function useRemoteData( {
199199

200200
// Log the error to the console for visibility.
201201
console.error( 'Remote Data Blocks query error:', err );
202-
203-
// Show a prominent notice.
204-
let message = err.message;
205-
if ( err instanceof RemoteDataFetchError && err.cause instanceof Error ) {
206-
message = `${ message }: ${ err.cause.message }`;
207-
}
208-
209-
createErrorNotice( message, {
210-
isDismissible: true,
211-
onDismiss: () => setError( undefined ),
212-
type: 'default',
213-
} );
214202
}
215203

216204
async function fetch( inputs: RemoteDataQueryInput[] ): Promise< void > {

0 commit comments

Comments
 (0)