Skip to content

Commit

Permalink
fix: throw error for empty body
Browse files Browse the repository at this point in the history
  • Loading branch information
sshivaditya committed Sep 13, 2024
1 parent a4bcc71 commit 6beefba
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/handlers/add-comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ export async function addComments(context: Context) {
adapters: { supabase },
} = context;
const { payload } = context as { payload: CommentPayload };
const markdown = payload.comment.body || null;
const markdown = payload.comment.body;
const authorId = payload.comment.user?.id || -1;
const nodeId = payload.comment.node_id;
const isPrivate = payload.repository.private;
const issueId = payload.issue.node_id;

try {
if (!markdown) {
throw new Error("Comment body is empty");
}
await supabase.comment.createComment(markdown, nodeId, authorId, payload, isPrivate, issueId);
} catch (error) {
if (error instanceof Error) {
Expand Down
3 changes: 3 additions & 0 deletions src/handlers/add-issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export async function addIssue(context: Context) {
const isPrivate = payload.repository.private;

try {
if (!markdown) {
throw new Error("Issue body is empty");
}
await supabase.issue.createIssue(nodeId, payload, isPrivate, markdown, authorId);
} catch (error) {
if (error instanceof Error) {
Expand Down
3 changes: 3 additions & 0 deletions src/handlers/update-comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export async function updateComment(context: Context) {
const markdown = payload.comment.body || null;
// Fetch the previous comment and update it in the db
try {
if (!markdown) {
throw new Error("Comment body is empty");
}
await supabase.comment.updateComment(markdown, nodeId, payload, isPrivate);
} catch (error) {
if (error instanceof Error) {
Expand Down
3 changes: 3 additions & 0 deletions src/handlers/update-issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export async function updateIssue(context: Context) {
const markdown = payload.issue.body + " " + payload.issue.title || null;
// Fetch the previous issue and update it in the db
try {
if (!markdown) {
throw new Error("Issue body is empty");
}
await supabase.issue.updateIssue(markdown, nodeId, payloadObject, isPrivate);
} catch (error) {
if (error instanceof Error) {
Expand Down

0 comments on commit 6beefba

Please sign in to comment.