next-drupal
next-drupal copied to clipboard
Debugging 422 errors when generating preview
I notice that the preview API callback handler has this:
} catch (error) {
return response.status(422).end()
}
That makes it a bit hard to debug why we're getting back a 422 response. Are there tips and tricks for debugging this in a containerized production environment where it isn't easy to say "oh just add some debugging quick." All of our secrets match up. I just have no idea where it's getting an error.
It's not preview URL validation as that handles !response.ok
so it must be in:
const validationPayload = await result.json()
response.setPreviewData({
resourceVersion,
plugin,
...validationPayload,
})
But I have no idea why. Do I just copy/paste this code and temporarily fork the preview endpoint?
Try configuring on Drupal in settings.php reverse proxy, for ex.:
$settings['reverse_proxy'] = TRUE; $settings['reverse_proxy_addresses'] = ['172.16.0.1']; // Depending on network configuration $settings['reverse_proxy_trusted_headers'] = \Symfony\Component\HttpFoundation\Request::HEADER_X_FORWARDED_FOR | \Symfony\Component\HttpFoundation\Request::HEADER_X_FORWARDED_HOST | \Symfony\Component\HttpFoundation\Request::HEADER_X_FORWARDED_PORT | \Symfony\Component\HttpFoundation\Request::HEADER_X_FORWARDED_PROTO | \Symfony\Component\HttpFoundation\Request::HEADER_FORWARDED;
Yep. That's configured and not the issue. This issue is about finding ways to get better error messages returned inside of the client here.
Have this very same issue using OOTB NextJs for Drupal. I have no idea why I am getting a 422 or where to begin debugging this issue.
In Drupal, I get this log but don't know where it is originating:
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException: No route found for "GET https://drupalnextjs.ddev.site/next/preview-url": Method Not Allowed (Allow: POST) in Symfony\Component\HttpKernel\EventListener\RouterListener->onKernelRequest() (line 131 of /var/www/html/vendor/symfony/http-kernel/EventListener/RouterListener.php).
The route definition for this from the NextJS module defines it as POST only.