nuxt-modules / prismic

Easily connect your Nuxt.js application to your content hosted on Prismic

Home Page:https://prismic.nuxtjs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

If Prismic endpoint is not available then complete website is down

jainsuneet opened this issue · comments

As per the documents I am injecting Prismic in the modules section of the nuxt.config.js.

modules: ['@nuxtjs/prismic' ],
prismic: {
    endpoint: 'https://your-repo-name.cdn.prismic.io/api/v2',
    linkResolver: '@/plugins/link-resolver',
    htmlSerializer: '@/plugins/html-serializer'
}

I am integrating prismic content as blog in my existing nuxt website at /blogs, I realized that if in case Prismic URL is not available (if Prismic server is down or URL is incorrect) then the complete website doesn't load at all (all routes are blocked).

Can you please suggest any workaround for this ?

commented

I think that's due to the plugin trying to get the API on injection (here). Perhaps it should just fail silently (loggin error but not throwing) or init the API not on load but only when requested 🤔

I think that's due to the plugin trying to get the API on injection (here). Perhaps it should just fail silently (loggin error but not throwing) or init the API not on load but only when requested

I am only including the plugin in modules of nuxt config and my app is universal. Not all the pages are using this plugin, only one page called /blog. Even the root of the website is blocked when there is no prismic related calls in index file. To init the API on load I tried to inject it as plugin instead of using in modules (the Vue way) but then it is not available for the server side rendering.

If it doesn't come from the instantiation of the api then I'm not sure I understand the issue. What does your blog page looks like? When you mention incorrect urls, do you mean that you try to query a non-existing document on Prismic? Also, does it happen on both dev and production?

I'll try to reproduce on my side!

If it doesn't come from the instantiation of the api then I'm not sure I understand the issue. What does your blog page looks like? When you mention incorrect urls, do you mean that you try to query a non-existing document on Prismic? Also, does it happen on both dev and production?

I'll try to reproduce on my side!

I just include it in nuxt.config file like I mentioned in my original question ... the blog page is not initialized so there is yet no query. An incorrect link in the nuxt.config blocks the complete application.

That's right, the js kit throws a 404 when used an invalid API endpoint.
Which is fine I believe, as not providing an endpoint simply defeats the purpose of such module. In your case, removing the module declaration until you need it seems preferable 👍

Let me know if you have another opinion on the matter ofc

That's right, the js kit throws a 404 when used an invalid API endpoint.
Which is fine I believe, as not providing an endpoint simply defeats the purpose of such module. In your case, removing the module declaration until you need it seems preferable 👍

Let me know if you have another opinion on the matter ofc

The root of Nuxt app is not calling the API but only /blogs is calling. For Nuxt it is injected in modules and the complete app is blocked. If an error is thrown then the app should load but this is not the case.

What happens when in production the prismic endpoint is down ? In that case my complete app is down as well.

The root of your app may not call the API but the module does when it injects prismic in your project.

The problem I can see with the module breaking here is if your app server-renders content and the endpoint somewhat becomes unavailable. And in other cases, you actually don't want your website to be rebuilt.

But as of today, if your website breaks because you don't provide the module with a valid endpoint, then you could simply not declare the module in the first place (until you input some content in your writing room)!

The root of your app may not call the API but the module does when it injects prismic in your project.

The problem I can see with the module breaking here is if your app server-renders content and the endpoint somewhat becomes unavailable. And in other cases, you actually don't want your website to be rebuilt.

But as of today, if your website breaks because you don't provide the module with a valid endpoint, then you could simply not declare the module in the first place (until you input some content in your writing room)!

An app cannot be exclusive for one module. There is no problem with the module loading but the error handling mechanism of this module. The bug should be resolved with this module otherwise all the Nuxt apps using this module will go down if the Prismic server is down.

Ok I'll leave open and see what I can do

commented

Closed in #85

@lihbr @hypervillain we've had our website go down twice this week even though I can see in our logs it says "Preventing fatal error". So seems like it's not actually preventing the error.

We're investigating our Prismic content to see if there's something broken on that side but thought I would comment on this issue as well.

@jainsuneet is this working fine for you after this fix?

commented

Hey @mmanousou, I'm sorry to hear that your website went down this week, we indeed had a minor outage for some customers on Tuesday.

In such cases, the trycatch statement we added should only prevent pages not relying on Prismic at all to fail (@jainsuneet use case). I retested to be sure, HTTP and URL errors caused by the module on those do not lead to a fatal as expected. If you want to prevent pages using Prismic from leading to fatal I guess you can wrap calls to Prismic inside trycatch statements, just like if you were querying a standard API.

I'm curious if you can share your Nuxt config file and module version to help us troubleshoot that further if you want ☺️

hey @lihbr thanks so much for getting back to me so quickly! I didn't try to access a non-prismic page at the time unfortunately. We always use try/catch for our Prismic calls but will have another look into it :/

We use nuxt 2.14.6 and @nuxtjs/prismic 1.2.4. Here's part of our nuxt config if it helps. Please let me know if i can provide more info.

modules: [
    '@nuxtjs/markdownit',
    ['@nuxtjs/pwa', { meta: false, icon: false, manifest: false }],
    ['@nuxtjs/icon', { iconSrc: './static/icon.png' }],
    '@nuxtjs/sitemap',
    '@nuxtjs/meta',
    ['@nuxtjs/proxy', { autoRewrite: true }],
    '@nuxtjs/sentry',
    'nuxt-trailingslash-module',
    'cookie-universal-nuxt'
  ],
buildModules: [
    '@nuxtjs/prismic'
  ],
prismic: {
    endpoint: process.env.CONTENT_URL,
    linkResolver: '@/plugins/link-resolver.js',
    htmlSerializer: '@/plugins/html-serializer.js',
    preview: '/preview'
  },`
commented

You're welcome! Config looks good to me, I guess you're using Nuxt SSR with Node right? (according to your modules) Not sure of what could cause it so far as long as your CONTENT_URL environment variable is filled correctly.

Happy to dig more into it if you figure out how to reproduce a fatal with a trycatch statement ☺️

@lihbr @hypervillain we've had our website go down twice this week even though I can see in our logs it says "Preventing fatal error". So seems like it's not actually preventing the error.

We're investigating our Prismic content to see if there's something broken on that side but thought I would comment on this issue as well.

@jainsuneet is this working fine for you after this fix?

There is still no proper solution, because of that we decided to move to another cms solution (Strapi). We cannot allow one module to break the whole website.

This is a worst case scenario but as @lihbr mentioned that they had an outage and any sort of outage on Prismic is directly impacting the website using it completely, even you are using Prismic only on your certain pages of website.