@@ -139,7 +139,7 @@ export default function TestimonialsModerationPage() {
139139 setLoadingItems ( true ) ;
140140 try {
141141 const widgetsRes = await fetch ( "/api/widgets" ) ;
142- const widgetsData = await widgetsRes . json ( ) ;
142+ const widgetsData = await widgetsRes . json ( ) . catch ( ( ) => ( { widgets : [ ] } ) ) ;
143143 if ( widgetsData . widgets ) {
144144 setWidgetsList ( widgetsData . widgets ) ;
145145 if ( widgetsData . widgets . length > 0 ) {
@@ -149,7 +149,7 @@ export default function TestimonialsModerationPage() {
149149 }
150150
151151 const testimonialsRes = await fetch ( "/api/testimonials" ) ;
152- const testimonialsData = await testimonialsRes . json ( ) ;
152+ const testimonialsData = await testimonialsRes . json ( ) . catch ( ( ) => ( { testimonials : [ ] } ) ) ;
153153 if ( testimonialsData . testimonials ) {
154154 setItems ( testimonialsData . testimonials ) ;
155155 }
@@ -188,11 +188,15 @@ export default function TestimonialsModerationPage() {
188188 } ) ,
189189 } ) ;
190190
191- const data = await res . json ( ) ;
191+ const data = await res . json ( ) . catch ( ( ) => ( {
192+ error : `Server responded with HTTP ${ res . status } : ${ res . statusText || "Unexpected error" } ` ,
193+ } ) ) ;
194+
192195 if ( res . ok && data . success ) {
193- if ( data . devApprovalUrl ) {
196+ const linkToCopy = data . approvalUrl || data . devApprovalUrl ;
197+ if ( linkToCopy ) {
194198 try {
195- await navigator . clipboard . writeText ( data . devApprovalUrl ) ;
199+ await navigator . clipboard . writeText ( linkToCopy ) ;
196200 } catch ( _ ) { }
197201 }
198202 if ( data . emailSent ) {
@@ -214,8 +218,8 @@ export default function TestimonialsModerationPage() {
214218 } else {
215219 showToast ( data . error || "Failed to send magic link." , "error" ) ;
216220 }
217- } catch {
218- showToast ( "Network error while sending magic link." , "error" ) ;
221+ } catch ( err : any ) {
222+ showToast ( err ?. message || "Network error while sending magic link." , "error" ) ;
219223 } finally {
220224 setSubmitting ( false ) ;
221225 }
@@ -229,11 +233,14 @@ export default function TestimonialsModerationPage() {
229233 headers : { "Content-Type" : "application/json" } ,
230234 body : JSON . stringify ( { testimonialId } ) ,
231235 } ) ;
232- const data = await res . json ( ) ;
236+ const data = await res . json ( ) . catch ( ( ) => ( {
237+ error : `Server responded with HTTP ${ res . status } : ${ res . statusText || "Unexpected error" } ` ,
238+ } ) ) ;
233239 if ( res . ok && data . success ) {
234- if ( data . approvalUrl ) {
240+ const linkToCopy = data . approvalUrl || data . devApprovalUrl ;
241+ if ( linkToCopy ) {
235242 try {
236- await navigator . clipboard . writeText ( data . approvalUrl ) ;
243+ await navigator . clipboard . writeText ( linkToCopy ) ;
237244 } catch ( _ ) { }
238245 }
239246 if ( data . emailSent ) {
@@ -247,8 +254,8 @@ export default function TestimonialsModerationPage() {
247254 } else {
248255 showToast ( data . error || "Failed to resend magic link." , "error" ) ;
249256 }
250- } catch {
251- showToast ( "Network error while resending link." , "error" ) ;
257+ } catch ( err : any ) {
258+ showToast ( err ?. message || "Network error while resending link." , "error" ) ;
252259 } finally {
253260 setResendingId ( null ) ;
254261 }
@@ -275,7 +282,9 @@ export default function TestimonialsModerationPage() {
275282 } ) ,
276283 } ) ;
277284
278- const data = await res . json ( ) ;
285+ const data = await res . json ( ) . catch ( ( ) => ( {
286+ error : `Server responded with HTTP ${ res . status } : ${ res . statusText || "Unexpected error" } ` ,
287+ } ) ) ;
279288 if ( res . ok && data . success ) {
280289 showToast ( "Offline praise successfully imported!" , "success" ) ;
281290 setShowImportModal ( false ) ;
@@ -286,8 +295,8 @@ export default function TestimonialsModerationPage() {
286295 } else {
287296 showToast ( data . error || "Import failed." , "error" ) ;
288297 }
289- } catch {
290- showToast ( "Network error while importing praise." , "error" ) ;
298+ } catch ( err : any ) {
299+ showToast ( err ?. message || "Network error while importing praise." , "error" ) ;
291300 } finally {
292301 setSubmitting ( false ) ;
293302 }
0 commit comments