File tree 1 file changed +26
-8
lines changed
1 file changed +26
-8
lines changed Original file line number Diff line number Diff line change 8
8
const apiUrl = 'https://api.jsonbin.io/v3/b/67c73db1e41b4d34e4a0bfb1/latest' ;
9
9
10
10
async function fetchPages ( ) {
11
- const response = await fetch ( apiUrl ) ;
12
- const data = await response . json ( ) ;
13
-
14
- console . log ( 'Fetched data:' , data ) ; // Log the response to check its structure
15
-
16
- // Check if data has a record property or handle the structure appropriately
17
- const pages = data . record || [ ] ; // Adjust based on actual response structure
18
- renderPages ( pages ) ;
11
+ try {
12
+ const response = await fetch ( apiUrl ) ;
13
+
14
+ // Check if the response is OK
15
+ if ( ! response . ok ) {
16
+ console . error ( "Failed to fetch data" , response . statusText ) ;
17
+ return ;
18
+ }
19
+
20
+ const data = await response . json ( ) ;
21
+ console . log ( 'Fetched data:' , data ) ; // Log the entire data object
22
+
23
+ // Assuming pages are located directly in the response (adjust as needed)
24
+ const pages = data . record || [ ] ; // If the pages are in a 'record' property, adjust accordingly
25
+ if ( Array . isArray ( pages ) ) {
26
+ renderPages ( pages ) ;
27
+ } else {
28
+ console . error ( "Pages data is not an array:" , pages ) ;
29
+ }
30
+ } catch ( error ) {
31
+ console . error ( "Error fetching pages:" , error ) ;
32
+ }
19
33
}
20
34
21
35
async function createPage ( ) {
57
71
const pagesDiv = document . getElementById ( 'pages' ) ;
58
72
pagesDiv . innerHTML = '' ;
59
73
74
+ if ( pages . length === 0 ) {
75
+ pagesDiv . innerHTML = '<p>No wikis found.</p>' ;
76
+ }
77
+
60
78
pages . forEach ( page => {
61
79
pagesDiv . innerHTML += `
62
80
<div class="card">
You can’t perform that action at this time.
0 commit comments