mirror of
https://github.com/chenasraf/express-otp.git
synced 2026-05-17 17:48:11 +00:00
36 lines
808 B
TypeScript
36 lines
808 B
TypeScript
/**
|
|
* The reason for an OTP error.
|
|
*
|
|
* - `no_user` - No user was found for the request.
|
|
* - `no_token` - No token was found in the request.
|
|
* - `invalid_token` - The token was invalid.
|
|
*/
|
|
export type OTPErrorReason = 'invalid_token' | 'no_token' | 'no_user'
|
|
|
|
/**
|
|
* The error thrown when OTP verification fails.
|
|
*/
|
|
export class OTPError {
|
|
/**
|
|
* The reason for the error.
|
|
* @param type The type of error.
|
|
*/
|
|
constructor(public type: OTPErrorReason) {}
|
|
|
|
/**
|
|
* The error message.
|
|
*/
|
|
public get message(): string {
|
|
switch (this.type) {
|
|
case 'invalid_token':
|
|
return 'Invalid token'
|
|
case 'no_token':
|
|
return 'No token provided'
|
|
case 'no_user':
|
|
return 'No user found'
|
|
default:
|
|
return `Unknown error: ${this.type}`
|
|
}
|
|
}
|
|
}
|