Some Search Results responses ending in `422 Unprocessable Content` based on `pageSize` value

In our website based on Next.js, we're witnessing some cases where the fulltext rest API (refer: https://prismic.io/docs/rest-api-technical-reference#fulltext) is resulting in error with Status Code: 422 Unprocessable Content for some cases.

The point worth mentioning is, the error is based on the pageSize parameter;
Our source-code snippet for search:

const fetchResults = async (searchQuery) => {
    const response = await client.query(
      [prismic.predicate.fulltext("document", searchQuery)],
      { pageSize: PRISMIC_PAGE_SIZE }
    );
    return response.results;
  };

The same searchQuery provides accurate results for a lower PRISMIC_PAGE_SIZE value.
Also, this PRISMIC_PAGE_SIZE value limit for 422 Unprocessable Content is also based on searchQuery, what it means is, example:

Let's say for searchQuery = "ABC", the 422 would be returned only for pageSize greater than 80
But, for searchQuery = "XYZ", the 422 would be returned even for pageSize greater than 25

In our use-case, we are setting the pageSize = 75 by default, but as there are certain cases found, where the API may return 422 Unprocessable Content even for pageSize > 25,

Just wanted to know what could be the reason for it, thanks and regards.

Hi @arorakartik4. I'm not sure what could be causing this. I'd like to try to reproduce the issue. Can you share the URL for your Prismic repository with me? If you don't want it to be public, you can send me a private message.

1 Like

Hi @Levi , thanks a lot for your response and time. I have shared with you the Prismic repository URL in a private message along with some other details, Kindly go through the details there. Regards.

Hi @arorakartik4,

Thanks for sharing your information in a private message. I recreated the error and then followed the Prismic URL that threw the error. This was the response I got:

The maximum size of response body is: 6 MO (6291456 bytes)
Your response is: 9.82 MO (10292401 bytes)

It looks like some of your documents might be exceptionally large, so they throw an error when you try to request them.

Sam

1 Like

Hi @samlittlefair,

Thanks a lot for looking into it and providing valuable insights. Will communicate with our content team to inform them. For our existing setup, I'm thinking about the best practical solution possible.

Can you kindly assist further with these two points if possible:

  1. This has to do with the total response size of the fulltext API response body right; is there a parameter in Rest API properties to limit the results by total body size, such that if it goes over the size limit, it may automatically limit the results, any possibility around this.
  2. Is there a convenient way to determine the individual document size on Prismic for better planning by the content team.

Any of this or any other suggestions from the Prismic team would be helpful, or another option would be to keep the pageSize parameter to a lower value with multiple API calls for our use case.

Regards.

Hi Kartik,

There is no automatic way to reduce the payload size, however I can recommend a few things that might help:

  • Use the fetch or graphQuery API options to query only the essential properties
  • Try opening and re-saving your documents in our new Page Builder, which has a more concise saving format
  • Write a retry mechanism into your code, so that a 422 error will trigger a new query with a smaller pageSize

I hope that helps!

Sam

1 Like