Skip to content

Commit

Permalink
refactor: enhance error handling and logging in handlers
Browse files Browse the repository at this point in the history
Improve error logger in github-webhook and refined chat creation log message.
  • Loading branch information
gentlementlegen committed Oct 13, 2024
1 parent 18475f2 commit d021a76
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/bot/mtproto-api/workrooms/create-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function createChat(context: Context<"issues.labeled", SupportedEve
return { status: 200, reason: "skipped" };
}

logger.info("Will attempt to create a new chat room...", { labelName });
logger.info(`Will attempt to create a new chat room '${chatName}'...`, { labelName });
const mtProto = new MtProto(context);
await mtProto.initialize();
let chatId: number;
Expand Down
9 changes: 4 additions & 5 deletions src/handlers/github-webhook.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Value } from "@sinclair/typebox/value";
import { Value, ValueError } from "@sinclair/typebox/value";
import { plugin } from "../plugin";
import { pluginSettingsSchema, pluginSettingsValidator, PluginInputs, Env } from "../types";
import { logger } from "../utils/logger";
Expand All @@ -8,12 +8,11 @@ export async function handleGithubWebhook(request: Request, env: Env): Promise<R
const webhookPayload = (await request.json()) as PluginInputs;
const settings = Value.Decode(pluginSettingsSchema, Value.Default(pluginSettingsSchema, webhookPayload.settings));
if (!pluginSettingsValidator.test(settings)) {
const errors: string[] = [];
const errors: ValueError[] = [];
for (const err of pluginSettingsValidator.errors(settings)) {
logger.error(err.message, { err });
errors.push(`${err.path}: ${err.message}`);
errors.push(err);
}
return new Response(JSON.stringify({ error: `Error: "Invalid settings provided. ${errors.join("; ")}"` }), {
return new Response(JSON.stringify({ error: logger.error(`Error: "Invalid settings provided."`, { errors }).logMessage.raw }), {
status: 400,
headers: { "content-type": "application/json" },
});
Expand Down

0 comments on commit d021a76

Please sign in to comment.