Skip to content

Commit

Permalink
fix: added error type to cognito base error class (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
sahinvardar authored Dec 18, 2023
1 parent 4a48173 commit 2483c34
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,26 @@ export enum RevokeTokenException {
UnsupportedTokenTypeException = 'UnsupportedTokenTypeException'
}

export type CognitoErrorType =
| 'CommonError'
| 'InitAuthError'
| 'RespondToAuthChallengeError'
| 'SignUpError'
| 'ConfirmSignUpError'
| 'ChangePasswordError'
| 'RevokeTokenError'
| 'ForgotPasswordError'
| 'ConfirmForgotPasswordError'
| 'ResendConfirmationCodeError'
| 'UpdateUserAttributesError'
| 'VerifyUserAttributeError'
| 'GlobalSignOutError';

export class CognitoError extends Error {
constructor(message: string) {
constructor(
message: string,
public readonly errorType: CognitoErrorType
) {
super(message);
}
}
Expand All @@ -412,7 +430,7 @@ export class CommonError extends CognitoError {
message: string,
public readonly cognitoException: CommonException
) {
super(message);
super(message, 'CommonError');
}
}

Expand All @@ -421,7 +439,7 @@ export class InitAuthError extends CognitoError {
message: string,
public readonly cognitoException: InitiateAuthException
) {
super(message);
super(message, 'InitAuthError');
}
}

Expand All @@ -430,7 +448,7 @@ export class RespondToAuthChallengeError extends CognitoError {
message: string,
public readonly cognitoException: RespondToAuthChallengeException
) {
super(message);
super(message, 'RespondToAuthChallengeError');
}
}

Expand All @@ -439,7 +457,7 @@ export class SignUpError extends CognitoError {
message: string,
public readonly cognitoException: SignUpException
) {
super(message);
super(message, 'SignUpError');
}
}

Expand All @@ -448,7 +466,7 @@ export class ConfirmSignUpError extends CognitoError {
message: string,
public readonly cognitoException: ConfirmSignUpException
) {
super(message);
super(message, 'ConfirmSignUpError');
}
}

Expand All @@ -457,7 +475,7 @@ export class ChangePasswordError extends CognitoError {
message: string,
public readonly cognitoException: ChangePasswordException
) {
super(message);
super(message, 'ChangePasswordError');
}
}

Expand All @@ -466,7 +484,7 @@ export class RevokeTokenError extends CognitoError {
message: string,
public readonly cognitoException: RevokeTokenException
) {
super(message);
super(message, 'RevokeTokenError');
}
}

Expand All @@ -475,7 +493,7 @@ export class ForgotPasswordError extends CognitoError {
message: string,
public readonly cognitoException: ForgotPasswordException
) {
super(message);
super(message, 'ForgotPasswordError');
}
}

Expand All @@ -484,7 +502,7 @@ export class ConfirmForgotPasswordError extends CognitoError {
message: string,
public readonly cognitoException: ConfirmForgotPasswordException
) {
super(message);
super(message, 'ConfirmForgotPasswordError');
}
}

Expand All @@ -493,7 +511,7 @@ export class ResendConfirmationCodeError extends CognitoError {
message: string,
public readonly cognitoException: ResendConfirmationException
) {
super(message);
super(message, 'ResendConfirmationCodeError');
}
}

Expand All @@ -502,7 +520,7 @@ export class UpdateUserAttributesError extends CognitoError {
message: string,
public readonly cognitoException: UpdateUserAttributesException
) {
super(message);
super(message, 'UpdateUserAttributesError');
}
}

Expand All @@ -511,7 +529,7 @@ export class VerifyUserAttributeError extends CognitoError {
message: string,
public readonly cognitoException: VerifyUserAttributeException
) {
super(message);
super(message, 'VerifyUserAttributeError');
}
}

Expand All @@ -520,6 +538,6 @@ export class GlobalSignOutError extends CognitoError {
message: string,
public readonly cognitoException: GlobalSignOutException
) {
super(message);
super(message, 'GlobalSignOutError');
}
}

0 comments on commit 2483c34

Please sign in to comment.