Fixed messages and comments for AuthErrors

ref #39
This commit is contained in:
Nicolai Ort 2020-12-20 18:41:25 +01:00
parent 7a4238f1f7
commit 4ca85a1f22

View File

@ -1,63 +1,57 @@
import { IsString } from 'class-validator'; import { IsString } from 'class-validator';
import { ForbiddenError, NotAcceptableError, NotFoundError, UnauthorizedError } from 'routing-controllers'; import { ForbiddenError, NotAcceptableError, NotFoundError, 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. * Error to throw when a jwt could not be parsed.
* For example: Wrong signature or expired.
*/ */
export class IllegalJWTError extends UnauthorizedError { export class IllegalJWTError extends UnauthorizedError {
@IsString() @IsString()
name = "IllegalJWTError" name = "IllegalJWTError"
@IsString() @IsString()
message = "your provided jwt could not be parsed" message = "Your provided jwt could not be parsed."
} }
/** /**
* Error to throw when user is nonexistant or refreshtoken is invalid. * Error to throw when user is nonexistant or refreshtoken is invalid.
* This can happen if someone provides a JWT with a invalid user id or the refreshTokenCount of the user is higher that the provided jwt's is.
*/ */
export class UserNonexistantOrRefreshtokenInvalidError extends UnauthorizedError { export class UserNonexistantOrRefreshtokenInvalidError extends UnauthorizedError {
@IsString() @IsString()
name = "UserNonexistantOrRefreshtokenInvalidError" name = "UserNonexistantOrRefreshtokenInvalidError"
@IsString() @IsString()
message = "user is nonexistant or refreshtoken is invalid" message = "User is nonexistant or refreshtoken is invalid."
} }
/** /**
* Error to throw when provided credentials are invalid. * Error to throw when provided credentials are invalid.
* We don't have seperate errors for username/mail and passwords to protect against guessing attacks.
*/ */
export class InvalidCredentialsError extends UnauthorizedError { export class InvalidCredentialsError extends UnauthorizedError {
@IsString() @IsString()
name = "InvalidCredentialsError" name = "InvalidCredentialsError"
@IsString() @IsString()
message = "your provided credentials are invalid" message = "Your provided credentials are invalid."
} }
/** /**
* Error to throw when a jwt does not have permission for this route/action. * Error to throw when a jwt does not have permission for this route/action.
* Mainly used be the @Authorized decorator (via the authchecker).
*/ */
export class NoPermissionError extends ForbiddenError { export class NoPermissionError extends ForbiddenError {
@IsString() @IsString()
name = "NoPermissionError" name = "NoPermissionError"
@IsString() @IsString()
message = "your provided jwt does not have permission for this route/ action" message = "Your provided jwt does not have permission for this route/ action."
} }
/** /**
* Error to throw when no username and no email is set. * Error to throw when no username and no email is set.
* Because we have to identify users somehow.
*/ */
export class UsernameOrEmailNeededError extends NotAcceptableError { export class UsernameOrEmailNeededError extends NotAcceptableError {
@IsString() @IsString()
@ -68,47 +62,48 @@ export class UsernameOrEmailNeededError extends NotAcceptableError {
} }
/** /**
* Error to throw when no password is provided. * Error to throw when no password is provided for a new user.
* Passwords are the minimum we need for user security.
*/ */
export class PasswordNeededError extends NotAcceptableError { export class PasswordNeededError extends NotAcceptableError {
@IsString() @IsString()
name = "PasswordNeededError" name = "PasswordNeededError"
@IsString() @IsString()
message = "no password is provided - you need to provide it" message = "No password is provided - you need to provide it."
} }
/** /**
* Error to throw when no user could be found mating the provided credential. * Error to throw when no user could be found for a certain query.
*/ */
export class UserNotFoundError extends NotFoundError { export class UserNotFoundError extends NotFoundError {
@IsString() @IsString()
name = "UserNotFoundError" name = "UserNotFoundError"
@IsString() @IsString()
message = "no user could be found for provided credential" message = "The user you provided couldn't be located in the system. \n Please check your request."
} }
/** /**
* Error to throw when no jwt token was provided (but one had to be). * Error to throw when no jwt was provided (but one had to be).
*/ */
export class JwtNotProvidedError extends NotAcceptableError { export class JwtNotProvidedError extends NotAcceptableError {
@IsString() @IsString()
name = "JwtNotProvidedError" name = "JwtNotProvidedError"
@IsString() @IsString()
message = "no jwt token was provided" message = "No jwt was provided."
} }
/** /**
* Error to throw when user was not found or refresh token count was invalid. * Error to throw when user was not found or the jwt's refresh token count was invalid.
*/ */
export class UserNotFoundOrRefreshTokenCountInvalidError extends NotAcceptableError { export class UserNotFoundOrRefreshTokenCountInvalidError extends NotAcceptableError {
@IsString() @IsString()
name = "UserNotFoundOrRefreshTokenCountInvalidError" name = "UserNotFoundOrRefreshTokenCountInvalidError"
@IsString() @IsString()
message = "user was not found or refresh token count was invalid" message = "User was not found or the refresh token count is invalid."
} }
/** /**
@ -119,5 +114,5 @@ export class RefreshTokenCountInvalidError extends NotAcceptableError {
name = "RefreshTokenCountInvalidError" name = "RefreshTokenCountInvalidError"
@IsString() @IsString()
message = "refresh token count was invalid" message = "Refresh token count is invalid."
} }