_Melly
March 11, 2024, 10:55am
1
System Information Strapi Version: 3.3.4
Operating System: macOS
Database: SQLlite
Node Version: 12.18
NPM Version:
Yarn Version:
Hi,
I was trying to add some custom validation logic in the “beforeCreate” lifecycle hook, but I was not able to customize the error message displayed in the UI , it is always returning the default one.
I tried to throw a “new Error”(“custom message”)" but no luck there.
Is it something doable ?
B.R
there is a similar discussion, but it doesnt work for me.
When i create error as it is written in docs:
const { errors } = require("@strapi/utils");
const { ApplicationError } = errors;
...
async beforeCreate(event) {
let okay = false;
// Throwing an error will prevent the entity from being created
if (!okay) {
throw new ApplicationError("Something went wrong", 400);
}
}
it is in the browser console, but doesnt show up in admin ui. my goal is to create custom validation in lifecycle in cases when it is not possible through admin page. then i want to show custom error to user in ui, so he would know why he cant save changes
_Melly
March 12, 2024, 3:31am
2
opened 07:06PM - 05 Mar 24 UTC
## Bug report
### Required System information
- Node.js version: 18.16.0
- … NPM version: 9.5.1
- Strapi version: 4.15.0
- Operating system: Windows and Mac
- Is your project Javascript or Typescript: TS
### Describe the bug
When throwing `throw new ApplicationError` in a controller or service strapi is returning "Internal Server Error" instead of the application error. This was not always the case although we have once seen this before due to a node version.
Now all of a sudden it is happening again on two different devices and we are not sure if some dependency has updated.
### Steps to reproduce the behavior
1. Controller throws 'throw new ApplicationError("You do not have permissions to do this")
2. Rest api querying said controller is receiving "Internal Server Error" instead of the application error
### Expected behavior
This behaviour has been before but we got rid of it by changing to node 18. Now it is happening again since we had an issue with strapi auto bumping to the next version and we downgraded back to 4.15.0.
### Screenshots
Query:
![image](https://github.com/strapi/strapi/assets/57114335/20304629-35ac-4a07-a19b-b0a7dd4132e9)
Controller:
![image](https://github.com/strapi/strapi/assets/57114335/c6c9c513-df31-4d14-8efd-6a3732114e48)
there is a fresh issue on github that resolved my problem.
i needed to upgrade my strapi packages versions from 4.20.3
to 4.20.4