/** * Inline fetch-failure state with retry. Errors render inline, never as * toasts (toasts are for success feedback). * * Auth failures mostly SELF-HEAL: rest.js refreshes the REST nonce via core's * admin-ajax `rest-nonce` action and retries once. What can still land here: * saddle_analytics_signed_out — the refresh itself failed: session is dead * rest_cookie_invalid_nonce — a fresh nonce was rejected too (rare) * rest_forbidden + 401 — credentials stripped before WordPress * rest_forbidden + 403 — signed in without manage_options */ import { __ } from '@wordpress/i18n'; import { useUi } from './ui-context'; // A dead session reloads into wp-login, which sends the user back here after. const reload = () => window.location.reload(); export default function LoadError( { onRetry, error } ) { const { Button, Notice } = useUi(); const status = error?.status; const code = error?.code; const line = ( text, label, onClick ) => (
{ text }
); if ( 'saddle_analytics_signed_out' === code ) { return line( __( 'Your sign-in has expired. Sign in again to continue.', 'saddle-analytics' ), __( 'Sign in again', 'saddle-analytics' ), reload ); } if ( 'rest_cookie_invalid_nonce' === code ) { return line( __( 'Your session could not be refreshed. Reload the page.', 'saddle-analytics' ), __( 'Reload', 'saddle-analytics' ), reload ); } if ( 401 === status ) { return line( __( 'WordPress saw this request as signed out. If a reload does not fix it, a security or cache layer is removing the sign-in.', 'saddle-analytics' ), __( 'Reload', 'saddle-analytics' ), reload ); } if ( 403 === status ) { return { __( 'This account can’t view Analytics. Sign in as an administrator.', 'saddle-analytics' ) }; } return line( __( 'Couldn’t load this data.', 'saddle-analytics' ), __( 'Retry', 'saddle-analytics' ), onRetry ); }