parent
7a4238f1f7
commit
4ca85a1f22
|
@ -1,63 +1,57 @@
|
|||
import { IsString } from 'class-validator';
|
||||
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.
|
||||
* For example: Wrong signature or expired.
|
||||
*/
|
||||
export class IllegalJWTError extends UnauthorizedError {
|
||||
@IsString()
|
||||
name = "IllegalJWTError"
|
||||
|
||||
@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.
|
||||
* 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 {
|
||||
@IsString()
|
||||
name = "UserNonexistantOrRefreshtokenInvalidError"
|
||||
|
||||
@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.
|
||||
* We don't have seperate errors for username/mail and passwords to protect against guessing attacks.
|
||||
*/
|
||||
export class InvalidCredentialsError extends UnauthorizedError {
|
||||
@IsString()
|
||||
name = "InvalidCredentialsError"
|
||||
|
||||
@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.
|
||||
* Mainly used be the @Authorized decorator (via the authchecker).
|
||||
*/
|
||||
export class NoPermissionError extends ForbiddenError {
|
||||
@IsString()
|
||||
name = "NoPermissionError"
|
||||
|
||||
@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.
|
||||
* Because we have to identify users somehow.
|
||||
*/
|
||||
export class UsernameOrEmailNeededError extends NotAcceptableError {
|
||||
@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 {
|
||||
@IsString()
|
||||
name = "PasswordNeededError"
|
||||
|
||||
@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 {
|
||||
@IsString()
|
||||
name = "UserNotFoundError"
|
||||
|
||||
@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 {
|
||||
@IsString()
|
||||
name = "JwtNotProvidedError"
|
||||
|
||||
@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 {
|
||||
@IsString()
|
||||
name = "UserNotFoundOrRefreshTokenCountInvalidError"
|
||||
|
||||
@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"
|
||||
|
||||
@IsString()
|
||||
message = "refresh token count was invalid"
|
||||
message = "Refresh token count is invalid."
|
||||
}
|
Loading…
Reference in New Issue