🚧 basic AuthErrors 🔒

ref #12
This commit is contained in:
Philipp Dormann 2020-12-04 22:17:03 +01:00
parent 1f3b312675
commit b9bbdee826
1 changed files with 68 additions and 0 deletions

68
src/errors/AuthError.ts Normal file
View File

@ -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"
}