Handle throwing custom error in document service middleware
Yohann Bethoule
Description
When throwing a custom error (e.g., ApplicationError) from a Document Service middleware, the Admin Panel displays a generic "Internal Server Error" (500) instead of the custom error message. This makes it impossible to provide meaningful feedback to users when implementing custom validation logic in Document Service middlewares.
Current Behavior
Document Service middlewares can throw ApplicationError with custom messages, but these are not properly handled by the Admin Panel. Instead of displaying the custom error message, users see a generic "Internal Server Error".
Expected Behavior
When a Document Service middleware throws an ApplicationError (or other custom errors), the Admin Panel should:
- Display the custom error message to the user
- Show the appropriate error status (e.g., 400 for validation errors, not 500)
- Allow users to understand what went wrong and how to fix it
Why This Matters
The v5 documentation explicitly recommends using Document Service middlewares over database lifecycle hooks, especially for draft & publish workflows. However, without proper error handling, it's impossible to implement user-friendly validation logic that provides meaningful feedback in the Admin Panel.
Related Issues
https://github.com/strapi/strapi/issues/24090 - Similar issue with error handling in Document Service middlewares