From b9bbdee82654b5cea26fdd97b38df2c0829ec1e6 Mon Sep 17 00:00:00 2001 From: Philipp Dormann Date: Fri, 4 Dec 2020 22:17:03 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20basic=20AuthErrors=20?= =?UTF-8?q?=F0=9F=94=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ref #12 --- src/errors/AuthError.ts | 68 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/errors/AuthError.ts diff --git a/src/errors/AuthError.ts b/src/errors/AuthError.ts new file mode 100644 index 0000000..24ded8a --- /dev/null +++ b/src/errors/AuthError.ts @@ -0,0 +1,68 @@ +import { IsString } from 'class-validator'; +import { ForbiddenError, NotAcceptableError, UnauthorizedError } from 'routing-controllers'; + +/** + * Error to throw when a jwt is expired + */ +export class ExpiredJWTError extends UnauthorizedError { + @IsString() + name = "ExpiredJWTError" + + @IsString() + message = "your provided jwt is expired" +} + +/** + * Error to throw when a jwt could not be parsed + */ +export class IllegalJWTError extends UnauthorizedError { + @IsString() + name = "IllegalJWTError" + + @IsString() + message = "your provided jwt could not be parsed" +} + +/** + * Error to throw when provided credentials are invalid + */ +export class InvalidCredentialsError extends UnauthorizedError { + @IsString() + name = "InvalidCredentialsError" + + @IsString() + message = "your provided credentials are invalid" +} + +/** + * Error to throw when a jwt does not have permission for this route/ action + */ +export class NoPermissionError extends ForbiddenError { + @IsString() + name = "NoPermissionError" + + @IsString() + message = "your provided jwt does not have permission for this route/ action" +} + +/** + * Error to thow when no username and no email is set + */ +export class UsernameOrEmailNeededError extends NotAcceptableError { + @IsString() + name = "UsernameOrEmailNeededError" + + @IsString() + message = "Auth needs to have email or username set! \n You provided neither." +} + +/** + * Error to thow when no password is provided + */ +export class PasswordNeededError extends NotAcceptableError { + @IsString() + name = "PasswordNeededError" + + @IsString() + message = "no password is provided - you need to provide it" +} \ No newline at end of file