Getting the following errors while fetching, there are several topics about this subject but none of them come up with a right answer. What can I do to remove these errors while fetching?
`=== [ Fetching wordpress__wp_me ] === http://localhost:8888/wordpress-gatsby/wp-json/wp/v2/users/me
⠈ source and transform nodesThe server response was "401 Unauthorized"
Inner exception message : "Je bent momenteel niet ingelogd."
Fetching the wordpress__wp_me took: 293.875ms
=== [ Fetching wordpress__wp_comments ] === http://localhost:8888/wordpress-gatsby/wp-json/wp/v2/comments
⢀ source and transform nodes -> wordpress__wp_comments fetched : 1
Fetching the wordpress__wp_comments took: 329.209ms
=== [ Fetching wordpress__wp_settings ] === http://localhost:8888/wordpress-gatsby/wp-json/wp/v2/settings
⠂ source and transform nodesThe server response was "401 Unauthorized"
Inner exception message : "Je hebt geen toestemming om dat te doen."
Fetching the wordpress__wp_settings took: 303.777ms
=== [ Fetching wordpress__acf_options ] === http://localhost:8888/wordpress-gatsby/wp-json/acf/v2/options
⠐ source and transform nodesThe server response was "404 Not Found"
Inner exception message : "Geen route gevonden die overeenkomt met de URL en aanvraagmethode"
Fetching the wordpress__acf_options took: 293.545ms`
Already installed latest version of Gatsby: "^1.9.277"
Uploaded posts with tags
gatsby-config.js: N/A
package.json: N/A
gatsby-node.js: N/A
gatsby-browser.js: N/A
gatsby-ssr.js: N/A
Those errors say you don't have permission to get some of the data. It shouldn't actually cause any problems. You can set verboseOutput to false in gatsby-config.js in wordpress plugin options
You are right, It's not causing any major issues. It's just annoying that the fetching displays errors. I have to show the process of fetching the data from Wordpress to a customer during a presentation. Is there a way to disable these errors?
Yeah, the errors could be a lot more tidy e.g. the plugin just collects which routes returned 403 and then at the end of the sourceNodes call it logs that out. Would you be interested in doing a PR?
Totally agree, it would be nice if non major errors will be displayed more tidy. I will add a PR for this issue.
You can also use excludedRoutes option in config ( https://www.gatsbyjs.org/packages/gatsby-source-wordpress/ ) to just exclude those routes - if you don't use them, you can as well skip trying to fetch them (which will speed things up and get rid of error message)
Perfect solution for this particular problem. Thank you!
I'm still getting the same errors after adding the below code in my gatsby-source-wordpress options:
excludedRoutes: ["/*/wp/v2/users/me", "/*/acf/v2/options", "/*/wp/v2/settings"],
Try excludedRoutes: ["/wp/v2/users/me", "/acf/v2/options", "/wp/v2/settings"],
That solved 2/3 errors, thank you!
One more error still displaying because the Wordpress Source plugin is trying to fetch data from the /acf/v2/options (v2 endpoint) of ACF. While all the other routes fetch from the /acf/v3/ route (as expected)
`Fetching the JSON data from 22 valid API Routes...
=== [ Fetching wordpress__acf_posts ] === http://localhost:8888/wordpress-gatsby/wp-json/acf/v3/posts
⠁ source and transform nodes -> wordpress__acf_posts fetched : 40
Fetching the wordpress__acf_posts took: 837.701ms
=== [ Fetching wordpress__acf_pages ] === http://localhost:8888/wordpress-gatsby/wp-json/acf/v3/pages
⠐ source and transform nodes -> wordpress__acf_pages fetched : 5
Fetching the wordpress__acf_pages took: 349.424ms
=== [ Fetching wordpress__acf_media ] === http://localhost:8888/wordpress-gatsby/wp-json/acf/v3/media
⠄ source and transform nodes -> wordpress__acf_media fetched : 0
Fetching the wordpress__acf_media took: 311.141ms
=== [ Fetching wordpress__acf_theme_styling ] === http://localhost:8888/wordpress-gatsby/wp-json/acf/v3/theme_styling
⠁ source and transform nodes -> wordpress__acf_theme_styling fetched : 2
Fetching the wordpress__acf_theme_styling took: 319.095ms
=== [ Fetching wordpress__acf_company ] === http://localhost:8888/wordpress-gatsby/wp-json/acf/v3/company
⠂ source and transform nodes -> wordpress__acf_company fetched : 64
Fetching the wordpress__acf_company took: 614.419ms
=== [ Fetching wordpress__acf_categories ] === http://localhost:8888/wordpress-gatsby/wp-json/acf/v3/categories
⠐ source and transform nodes -> wordpress__acf_categories fetched : 1
Fetching the wordpress__acf_categories took: 315.559ms
=== [ Fetching wordpress__acf_tags ] === http://localhost:8888/wordpress-gatsby/wp-json/acf/v3/tags
⡀ source and transform nodes -> wordpress__acf_tags fetched : 0
Fetching the wordpress__acf_tags took: 304.783ms
=== [ Fetching wordpress__acf_comments ] === http://localhost:8888/wordpress-gatsby/wp-json/acf/v3/comments
⠁ source and transform nodes -> wordpress__acf_comments fetched : 1
Fetching the wordpress__acf_comments took: 313.316ms
=== [ Fetching wordpress__acf_users ] === http://localhost:8888/wordpress-gatsby/wp-json/acf/v3/users
⠠ source and transform nodes -> wordpress__acf_users fetched : 1
Fetching the wordpress__acf_users took: 320.387ms
=== [ Fetching wordpress__POST ] === http://localhost:8888/wordpress-gatsby/wp-json/wp/v2/posts
⠐ source and transform nodes -> wordpress__POST fetched : 40
Fetching the wordpress__POST took: 570.182ms
=== [ Fetching wordpress__PAGE ] === http://localhost:8888/wordpress-gatsby/wp-json/wp/v2/pages
⢀ source and transform nodes -> wordpress__PAGE fetched : 5
Fetching the wordpress__PAGE took: 345.070ms
=== [ Fetching wordpress__wp_media ] === http://localhost:8888/wordpress-gatsby/wp-json/wp/v2/media
⠁ source and transform nodes -> wordpress__wp_media fetched : 0
Fetching the wordpress__wp_media took: 305.417ms
=== [ Fetching wordpress__wp_theme_styling ] === http://localhost:8888/wordpress-gatsby/wp-json/wp/v2/theme_styling
⠐ source and transform nodes -> wordpress__wp_theme_styling fetched : 2
Fetching the wordpress__wp_theme_styling took: 320.365ms
=== [ Fetching wordpress__wp_company ] === http://localhost:8888/wordpress-gatsby/wp-json/wp/v2/company
⠈ source and transform nodes -> wordpress__wp_company fetched : 64
Fetching the wordpress__wp_company took: 603.476ms
=== [ Fetching wordpress__wp_types ] === http://localhost:8888/wordpress-gatsby/wp-json/wp/v2/types
⢀ source and transform nodes -> wordpress__wp_types fetched : 1
Fetching the wordpress__wp_types took: 299.370ms
=== [ Fetching wordpress__wp_statuses ] === http://localhost:8888/wordpress-gatsby/wp-json/wp/v2/statuses
⠂ source and transform nodes -> wordpress__wp_statuses fetched : 1
Fetching the wordpress__wp_statuses took: 299.529ms
=== [ Fetching wordpress__wp_taxonomies ] === http://localhost:8888/wordpress-gatsby/wp-json/wp/v2/taxonomies
⠐ source and transform nodes -> wordpress__wp_taxonomies fetched : 1
Fetching the wordpress__wp_taxonomies took: 301.703ms
=== [ Fetching wordpress__CATEGORY ] === http://localhost:8888/wordpress-gatsby/wp-json/wp/v2/categories
⠄ source and transform nodes -> wordpress__CATEGORY fetched : 2
Fetching the wordpress__CATEGORY took: 307.269ms
=== [ Fetching wordpress__TAG ] === http://localhost:8888/wordpress-gatsby/wp-json/wp/v2/tags
⠁ source and transform nodes -> wordpress__TAG fetched : 0
Fetching the wordpress__TAG took: 317.537ms
=== [ Fetching wordpress__wp_users ] === http://localhost:8888/wordpress-gatsby/wp-json/wp/v2/users
⠠ source and transform nodes -> wordpress__wp_users fetched : 1
Fetching the wordpress__wp_users took: 315.519ms
=== [ Fetching wordpress__wp_comments ] === http://localhost:8888/wordpress-gatsby/wp-json/wp/v2/comments
⠄ source and transform nodes -> wordpress__wp_comments fetched : 1
Fetching the wordpress__wp_comments took: 313.143ms
=== [ Fetching wordpress__acf_options ] === http://localhost:8888/wordpress-gatsby/wp-json/acf/v2/options
⠐ source and transform nodesThe server response was "404 Not Found"`
Any idea why this happens?
In case anyone else ends up here. The way to fix this could be case by case. My suggestion is to pattern match the paths you're getting with a 401 error.
For example, this is what appears during the build:
Path: /wp-json/wp/v2/users/me?per_page=100&page=1
The server response was "401 Unauthorized"
Inner exception message: "You are not currently logged in."
There are a lot more but in this case, the path we need to exclude is:
"/wp/v2/users/me"
excludedRoutes: [
"/wp/v2/users/me",
"/acf/v2/options",
"/wp/v2/settings",
"/wp/v2/themes",
],
If there is a path that's blocked and you do need access to it I suggest using the JWT plugin to gain the auth you need.
https://wordpress.org/plugins/jwt-authentication-for-wp-rest-api/
Most helpful comment
Try
excludedRoutes: ["/wp/v2/users/me", "/acf/v2/options", "/wp/v2/settings"],