Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully handle API 404 when no data present #6

Open
pdclark opened this issue Oct 20, 2021 · 0 comments
Open

Gracefully handle API 404 when no data present #6

pdclark opened this issue Oct 20, 2021 · 0 comments

Comments

@pdclark
Copy link

pdclark commented Oct 20, 2021

Possibly related: https://stackoverflow.com/questions/67503965/why-i-miss-some-data-on-querying-of-chrome-ux-report-api

When no data is present in the Chrome API, the API returns a 404.
This causes a 404 in the console, and no admin menu appears on the front-end.

Screen Shot 2021-10-20 at 12 14 10 PM

Uncaught (in promise) Error: chrome ux report data not found
    at generateReport (script.js?ver=1.0:17)
const CrUXApiUtil = {};
CrUXApiUtil.KEY = wpWebVitals.cruxApiKey;

// Gather the data for example.com and display it
async function generateReport() {
	const endpointUrl = 'https://chromeuxreport.googleapis.com/v1/records:queryRecord';
	const resp = await fetch( `${endpointUrl}?key=${CrUXApiUtil.KEY}`, {
		method: 'POST',
		body: JSON.stringify( {
			origin: window.location.href
		} ),
	} );

	const json = await resp.json();

	if (!resp.ok) {
➡️		throw new Error( json.error.message );
	}

Expected results:

The menu should display with some error message letting the user know that no data was returned from the API and to please wait (or do whatever else it takes to resolve the issue.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant