Unexpected error on URL when querying Prismic content in metalsmith?

Hello!

I inherited a site built in metalsmith (a static site generator) that uses prismic for content management. I’m running into an intermittent error when I run our build command that seems to be query/timeout related. Looks like the error has something to do with node_modules/prismic.io/lib/requests.js and node_modules/metalsmith-prismic-server/src/dev-server.js

Not quite sure what to do next in terms of troubleshooting as this error happened occasionally at first and is now happening 75% of the time when I run things locally. Any help would be greatly appreciated.

Error message below:

Error: Unexpected error on URL https://dronedeploy-www.cdn.prismic.io/api/v1/documents/search?q=%5B%5B%3Ad%20%3D%20any(document.type%2C%20%5B%22webinar%22%2C%22ebook%22%2C%22series%22%2C%22event%22%2C%22story%22%5D)%5D%5D&q=%5B%5B%3Ad%20%3D%20any(document.type%2C%20%5B%22ebook%22%2C%20%22webinar%22%2C%20%22series%22%2C%20%22story%22%5D)%5D%5D&page=6&access_token=XXXX&ref=XxjShBIAACEA0b2U
    at ClientRequest.<anonymous> (/Users/nikibrown/Code/landing_page/node_modules/prismic.io/lib/requests.js:199:18)
    at ClientRequest.emit (events.js:315:20)
    at TLSSocket.socketOnEnd (_http_client.js:453:9)
    at TLSSocket.emit (events.js:327:22)
    at endReadableNT (_stream_readable.js:1221:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
(node:98992) UnhandledPromiseRejectionWarning: Error: Unexpected error on URL https://dronedeploy-www.cdn.prismic.io/api/v1/documents/search?q=%5B%5B%3Ad%20%3D%20any(document.type%2C%20%5B%22webinar%22%2C%22ebook%22%2C%22series%22%2C%22event%22%2C%22story%22%5D)%5D%5D&q=%5B%5B%3Ad%20%3D%20any(document.type%2C%20%5B%22ebook%22%2C%20%22webinar%22%2C%20%22series%22%2C%20%22story%22%5D)%5D%5D&page=6&access_token=XXXX&ref=XxjShBIAACEA0b2U
    at ClientRequest.<anonymous> (/Users/nikibrown/Code/landing_page/node_modules/prismic.io/lib/requests.js:199:18)
    at ClientRequest.emit (events.js:315:20)
    at TLSSocket.socketOnEnd (_http_client.js:453:9)
    at TLSSocket.emit (events.js:327:22)
    at endReadableNT (_stream_readable.js:1221:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
(node:98992) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:98992) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
/Users/nikibrown/Code/landing_page/node_modules/metalsmith-prismic-server/src/dev-server.js:29
        throw err;
        ^

Thanks!

  • N

Hi Niki,

It’s sounds like something that might be related to the master ref the kit is using when querying the API. If you visit the URL in the error do you get the data returned?

Hi Phil

Are you referring to this URL in my error message?

https://dronedeploy-www.cdn.prismic.io/api/v1/documents/search?q=[[%3Ad%20%3D%20any(document.type%2C%20["webinar"%2C"ebook"%2C"series"%2C"event"%2C"story"])]]&q=[[%3Ad%20%3D%20any(document.type%2C%20["ebook"%2C%20"webinar"%2C%20"series"%2C%20"story"])]]&page=6&access_token=XXXX&ref=XxjShBIAACEA0b2U

If so then yes this returns the expected data.

Any other thoughts?

OK, in that case it lets me know that the correct information is coming from the API.

This narrows it down to something in your project. My first guess would be maybe that the master ref isn’t being updated automatically. Do you know how the ref is being passed to the URL?

Hi Phil

As far as I can tell we are using https://github.com/mbanting/metalsmith-prismic but we have our Prismic URL stored in an .env file which is set to https://dronedeploy-www.prismic.io/api

Thanks,

N

Is there any chance you could forward us a github link for your project so that we can investigate further?

Hi Phil - what is your github username? This is a private github repo and I’ll need to check with my team.

Thanks!

  • N

Sure, it’s phillysnow.

Phil - you should be all set to access to our repo. Let me know if you have any questions or need anything else.

Thanks

N

Thanks, I’ll look in to this today.

Hi Phil

Any updates?

Thanks,

  • N

Fix update: We found two things that make the project build correctly for this case:

  1. The correct endpoint that you should configure should always use the API v2 instead of v1.
  2. Adding a conditional statement that checks if a slice is being retrieved or not also prevents the site from breaking.

After that, the project should work properly.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.