Skip to content

Commit

Permalink
feat: Add panic
Browse files Browse the repository at this point in the history
  • Loading branch information
MikuroXina committed Mar 21, 2021
1 parent e002397 commit 939b0f4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/bot/abst/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export interface Message {
withTyping(callee: () => Promise<boolean>): Promise<boolean>;
reply(message: string): Promise<void>;
sendEmbed(embed: MessageEmbed): Promise<void>;
panic(reason: unknown): never;
}
3 changes: 1 addition & 2 deletions src/bot/play/subscribe/mark-as-read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type { Message } from "../../abst/message";
import { MessageEmbed } from "discord.js";
import type { NotificationApi } from "../../abst/api";
import type { UserDatabase } from "../../abst/user-database";
import { fetchErrorHandler } from "../../skin/fetch-error-handler";
import { replyFailure } from "../../abst/reply-failure";

const markPattern = /^\/ghm (?<notification>[0-9]+)\s*$/u;
Expand Down Expand Up @@ -34,7 +33,7 @@ export const markAsRead = (
query,
}),
)
.catch(fetchErrorHandler((embed) => msg.sendEmbed(embed)));
.catch(msg.panic);
};

const markNotificationAsRead = ({
Expand Down
5 changes: 1 addition & 4 deletions src/bot/play/subscribe/subscribe-notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { CommandProcessor } from "../../abst/connector";
import type { Message } from "../../abst/message";
import type { UserApi } from "src/bot/abst/api";
import type { UserDatabase } from "../../abst/user-database";
import { fetchErrorHandler } from "../../skin/fetch-error-handler";

const subscribePattern = /^\/ghs (?<name>[^/:?]+) (?<token>[^/:?]+)\s*$/u;

Expand All @@ -23,9 +22,7 @@ export const subscribeNotification = (
return false;
}

const user = await query
.getGitHubUser(name, token)
.catch(fetchErrorHandler((mes) => msg.sendEmbed(mes)));
const user = await query.getGitHubUser(name, token).catch(msg.panic);

await db.register(msg.getAuthorId(), user);

Expand Down
11 changes: 11 additions & 0 deletions src/bot/skin/discord-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,15 @@ export class DiscordMessage implements Message {
async sendEmbed(embed: MessageEmbed): Promise<void> {
await this.raw.channel.send(embed);
}

panic(reason: unknown): never {
const yellow = 0xffc208;
this.sendEmbed(
new MessageEmbed()
.setColor(yellow)
.setTitle("エラー発生, リトライはされません")
.setDescription(reason),
);
throw reason;
}
}
5 changes: 5 additions & 0 deletions src/bot/skin/mock-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ export class MockMessage implements Message {
this.emitter.emit("sendEmbed", embed);
return Promise.resolve();
}

panic(reason: unknown): never {
console.error(reason);
throw reason;
}
}

0 comments on commit 939b0f4

Please sign in to comment.