mirror of
https://github.com/logto-io/logto.git
synced 2025-03-24 22:41:28 -05:00
refactor(core): remove InvalidInputError (#1477)
This commit is contained in:
parent
b1a99c9029
commit
be0d9326e4
5 changed files with 10 additions and 5 deletions
|
@ -8,7 +8,6 @@
|
|||
* ForeignKeyIntegrityConstraintViolationError,
|
||||
* IntegrityConstraintViolationError,
|
||||
* InvalidConfigurationError,
|
||||
* InvalidInputError,
|
||||
* NotFoundError,
|
||||
* NotNullIntegrityConstraintViolationError,
|
||||
* StatementCancelledError,
|
||||
|
|
|
@ -234,7 +234,7 @@ describe('adminUserRoutes', () => {
|
|||
);
|
||||
await expect(
|
||||
userRequest.patch('/users/foo').send({ roleNames: ['admin'] })
|
||||
).resolves.toHaveProperty('status', 500);
|
||||
).resolves.toHaveProperty('status', 400);
|
||||
expect(findUserById).toHaveBeenCalledTimes(1);
|
||||
expect(updateUserById).not.toHaveBeenCalled();
|
||||
});
|
||||
|
|
|
@ -2,7 +2,6 @@ import { arbitraryObjectGuard, userInfoSelectFields } from '@logto/schemas';
|
|||
import { passwordRegEx, usernameRegEx } from '@logto/shared';
|
||||
import { has } from '@silverhand/essentials';
|
||||
import pick from 'lodash.pick';
|
||||
import { InvalidInputError } from 'slonik';
|
||||
import { literal, object, string } from 'zod';
|
||||
|
||||
import RequestError from '@/errors/RequestError';
|
||||
|
@ -134,8 +133,13 @@ export default function adminUserRoutes<T extends AuthedRouter>(router: T) {
|
|||
const resourcesNotFound = roleNames.filter(
|
||||
(roleName) => !roles.some(({ name }) => roleName === name)
|
||||
);
|
||||
// TODO: Should be cached by the error handler and return request error
|
||||
throw new InvalidInputError(`role names (${resourcesNotFound.join(',')}) are not valid`);
|
||||
throw new RequestError({
|
||||
status: 400,
|
||||
code: 'user.invalid_role_names',
|
||||
data: {
|
||||
roleNames: resourcesNotFound.join(','),
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -579,6 +579,7 @@ const errors = {
|
|||
phone_not_exists: 'The phone number has not been registered yet.',
|
||||
identity_not_exists: 'The social account has not been registered yet.',
|
||||
identity_exists: 'The social account has been registered.',
|
||||
invalid_role_names: 'role names ({{roleNames}}) are not valid',
|
||||
},
|
||||
password: {
|
||||
unsupported_encryption_method: 'The encryption method {{name}} is not supported.',
|
||||
|
|
|
@ -557,6 +557,7 @@ const errors = {
|
|||
phone_not_exists: '手机号码尚未注册',
|
||||
identity_not_exists: '该社交帐号尚未注册',
|
||||
identity_exists: '该社交帐号已被注册',
|
||||
invalid_role_names: '角色名称({{roleNames}})无效',
|
||||
},
|
||||
password: {
|
||||
unsupported_encryption_method: '不支持的加密方法 {{name}}',
|
||||
|
|
Loading…
Add table
Reference in a new issue