Skip to content

Commit

Permalink
Add cause to TokenRotationError (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch authored Apr 25, 2024
1 parent d2ac7e0 commit b970376
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ export class SlackAPIError extends Error {
}

export class TokenRotationError extends Error {
constructor(message: string) {
cause: Error;
constructor(message: string, cause: Error) {
super(message);
this.name = "TokenRotationError";
this.cause = cause;
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/token-rotation/token-rotator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export class TokenRotator {
};
}
} catch (e) {
throw new TokenRotationError(`Failed to refresh a bot token: ${e}`);
throw new TokenRotationError(
`Failed to refresh a bot token: ${e}`,
e as Error,
);
}
}
if (targets.user && targets.user.token_expires_at < expireAt) {
Expand All @@ -68,7 +71,10 @@ export class TokenRotator {
};
}
} catch (e) {
throw new TokenRotationError(`Failed to refresh a user token: ${e}`);
throw new TokenRotationError(
`Failed to refresh a user token: ${e}`,
e as Error,
);
}
}
return refreshResults;
Expand Down
4 changes: 3 additions & 1 deletion src_deno/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@ export class SlackAPIError extends Error {
}

export class TokenRotationError extends Error {
constructor(message: string) {
cause: Error;
constructor(message: string, cause: Error) {
super(message);
this.name = "TokenRotationError";
this.cause = cause;
}
}

Expand Down
10 changes: 8 additions & 2 deletions src_deno/token-rotation/token-rotator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export class TokenRotator {
};
}
} catch (e) {
throw new TokenRotationError(`Failed to refresh a bot token: ${e}`);
throw new TokenRotationError(
`Failed to refresh a bot token: ${e}`,
e as Error,
);
}
}
if (targets.user && targets.user.token_expires_at < expireAt) {
Expand All @@ -68,7 +71,10 @@ export class TokenRotator {
};
}
} catch (e) {
throw new TokenRotationError(`Failed to refresh a user token: ${e}`);
throw new TokenRotationError(
`Failed to refresh a user token: ${e}`,
e as Error,
);
}
}
return refreshResults;
Expand Down

0 comments on commit b970376

Please sign in to comment.