fix: handle user not found error

This commit is contained in:
kayac-chang 2022-01-14 14:23:04 +08:00
parent ce09d38972
commit 04d8de7c38

View File

@ -12,7 +12,7 @@ const { getService } = require('../utils');
const { validateCreateUserBody, validateUpdateUserBody } = require('./validation/user');
const { sanitize } = utils;
const { ApplicationError, ValidationError } = utils.errors;
const { ApplicationError, ValidationError, NotFoundError } = utils.errors;
const sanitizeOutput = (user, ctx) => {
const schema = strapi.getModel('plugin::users-permissions.user');
@ -91,6 +91,9 @@ module.exports = {
const { email, username, password } = ctx.request.body;
const user = await getService('user').fetch({ id });
if (!user) {
throw new NotFoundError(`User with ${id} not existed`);
}
await validateUpdateUserBody(ctx.request.body);