System Information
- Strapi Version: 4.7.1
- Operating System: linux ubuntu 22.04
- Database: PostgreSQL
- Node Version: v16.18.0
- NPM Version: 8.19.2
Hi I need to create custom error message on auth login endpoint. My solution is to create
middleware such like
// path to my file: src/middlewares/badRequestError.js
module.exports = () => {
return async (ctx, next) => {
if (ctx.request.url === "/api/auth/local" && ctx.response.status === 400) {
return ctx.badRequest("Email or password - invalid. Please try again");
}
await next();
};
};
And Also I set up my middleware to file config/middleware.ts
module.exports = [
"strapi::errors",
"strapi::security",
"strapi::cors",
"strapi::poweredBy",
"strapi::logger",
"strapi::query",
"strapi::body",
"strapi::session",
"strapi::favicon",
"strapi::public",
"global::badRequestErorr",
{
resolve: "../src/middlewares/badRequestErorr.js",
config: {},
},
];