System Information
- Strapi Version: 4.20.1
- Operating System: MacOs
- Database: -
- Node Version: -
- NPM Version: -
- Yarn Version: -
During an update/migration of a controller that works in version 4.14.5, to a Strapi project running version 4.20.1, I get the error that “ctx.badRequest” is not a function.
After doing I little research, I notice that this is a function that is part of the koa-respond package. I assume this pack is no longer part of the Strapi core. Hence I should rewrite it to something else.
There is no migration guide that describes this issue, going to the package.json of version 4.14.5 doesn’t mention koa (nor koa-respond) neither. So that might invalidate my thought process entirely. What strategy can you suggest to resolve issues as such?
module.exports = factories.createCoreController('api::lorem.lorem', ({
strapi
}) => ({
async create(ctx) {
const requiredFields = ['name', 'role'];
const {
accent_color,
name,
role
} = ctx.request.body.data;
// Check if all required fields are present
const missingFields = requiredFields.filter(field => !ctx.request.body.data[field])
if (missingFields.length > 0) {
return ctx.badRequest(null, [{
messages: [{
id: 'ValidationError',
message: `Missing required fields: ${missingFields.join(', ')}`,
}, ],
}, ]);
}
})