Sometimes when editing a post or a page in WordPress, the site just crashes with the error “The editor has encountered an unexpected error.” Let’s take a deeper look and try to fix this problem. Note: This is what ultimately solved it for me, but doesn’t necessary need to be the cause of your error.
As mentioned before, sometimes when editing a page or post, the site would crash with the error
"The editor has encountered an unexpected error."
Additionally, some default WordPress blocks do not appear to work properly, such as the query_loop block, which would throw
"The block has encountered an error and cannot be previewed".
The site health tool actually also informs us about a problem with the REST API
"The REST API did not process the context query parameter correctly."
For an untrained user, such as myself, all these observations seem to be unrelated. However because the REST API does behave incorrectly, it results in the unexpected errors depicted above, which also just appears in some specific cases. After troubleshooting and looking for potential error sources, I came to the conclusion, that it had to do something with Caddy not rewritting the query appropriately.
Now having the correct query strings, i came upon someone with almost the exact problem who posted his findings in the caddy forum. Quickly applying the changes in my own Caddyfile configuration resolved the REST API warning and unexpected error messages.
If this helped you or you stumbled upon another resolution, feel free to leave a comment 🙂