From a0e6424d482c54d77a887d8b91c81a6f39b51f59 Mon Sep 17 00:00:00 2001 From: Philipp Dormann Date: Fri, 4 Dec 2020 17:53:28 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20better/=20more=20errors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ref #14 --- src/errors/CreateUserErrors.ts | 24 ----------------- src/errors/UserErrors.ts | 47 ++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 24 deletions(-) delete mode 100644 src/errors/CreateUserErrors.ts create mode 100644 src/errors/UserErrors.ts diff --git a/src/errors/CreateUserErrors.ts b/src/errors/CreateUserErrors.ts deleted file mode 100644 index 3b28735..0000000 --- a/src/errors/CreateUserErrors.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { NotFoundError } from 'routing-controllers'; -import { IsString } from 'class-validator'; - -/** - * Error to throw when a usergroup couldn't be found. - */ -export class UserGroupNotFoundError extends NotFoundError { - @IsString() - name = "UserGroupNotFoundError" - - @IsString() - message = "User Group not found!" -} - -/** - * Error to throw when no username or email is set - */ -export class UsernameOrEmailNeededError extends NotFoundError { - @IsString() - name = "UsernameOrEmailNeededError" - - @IsString() - message = "no username or email is set!" -} diff --git a/src/errors/UserErrors.ts b/src/errors/UserErrors.ts new file mode 100644 index 0000000..4c9e98b --- /dev/null +++ b/src/errors/UserErrors.ts @@ -0,0 +1,47 @@ +import { IsString } from 'class-validator'; +import { NotAcceptableError, NotFoundError } from 'routing-controllers'; + +/** + * Error to throw when a usergroup couldn't be found. + */ +export class UserGroupNotFoundError extends NotFoundError { + @IsString() + name = "UserGroupNotFoundError" + + @IsString() + message = "User Group not found!" +} + +/** + * Error to throw when no username or email is set + */ +export class UsernameOrEmailNeededError extends NotFoundError { + @IsString() + name = "UsernameOrEmailNeededError" + + @IsString() + message = "no username or email is set!" +} + +/** + * Error to throw when a user couldn't be found. + */ +export class UserNotFoundError extends NotFoundError { + @IsString() + name = "UserNotFoundError" + + @IsString() + message = "User not found!" +} + +/** + * Error to throw when two users' ids don't match. + * Usually occurs when a user tries to change a user's id. + */ +export class UserIdsNotMatchingError extends NotAcceptableError { + @IsString() + name = "UserIdsNotMatchingError" + + @IsString() + message = "The id's don't match!! \n And if you wanted to change a user's id: This isn't allowed" +} \ No newline at end of file