Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor improvements #5

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

TheColorDarkBlue
Copy link

@TheColorDarkBlue TheColorDarkBlue commented Nov 29, 2024

  • Run ESLint/Prettier/dprint on main.ts
  • Proofread/improve README
  • Remove unused test file: example.test.ts
  • Remove unused Context import from Devvit API
  • Make comments more concise/to-the-point/clear

@TheColorDarkBlue TheColorDarkBlue changed the title Proofread repo Proofread repo. Minor improvements Nov 29, 2024
@TheColorDarkBlue TheColorDarkBlue changed the title Proofread repo. Minor improvements Minor improvements to main.ts and README Nov 29, 2024
@TheColorDarkBlue TheColorDarkBlue changed the title Minor improvements to main.ts and README Minor improvements Dec 6, 2024
@huncyrus
Copy link

huncyrus commented Dec 9, 2024

Added a few comment, note and recommendation if you don't mind :)

Copy link

@huncyrus huncyrus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some note & advice

## Setup Instructions

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider to add requirements for the project (exact Node version, any kind of keys for webhook, etc)

onEvent: async (event: ModMail, context: TriggerContext) => {
try {
if (!context) {
throw new Error('Context is probably undefined');
throw new Error("Context is probably undefined");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add logging here with context and details (what failed, why failed)

}

await sendModMailToWebhook(event, context);
} catch (error: any) {
console.error('There was an error:', error.message);
console.error("There was an error:", error.message);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add meaningful error messages (why it failed, what failed)
Also, consider adding the entire error instead of the error.message to have stack trace and all possible details

return;
}

const conversationId = event.conversationId ?? '';
const actualConversationId = conversationId.replace('ModmailConversation_', '');
const conversationId = event.conversationId ?? "";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a check for the conversationId to handle missing data or possible error(s).


if (!lastMessage) {
console.error('No messages found');
console.error("No messages found");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider to add a meaningful / informative error message with context and details.
Example:
console.error('No last message found. Terminating process. Message id: ', messageIds, '\n lastMessageId: ', lastMessageId, '\n conversationId: ', conversationId);
Such a verbose message gives you immediate context of what happens and details so you don't have to investigate or re-trigger something to have actual data.

const authorProfileLink = `https://www.reddit.com/u/${authorName}`;

if (participatingAs === 'moderator' && !outgoing) {
console.log('Not sending outgoing messages to the webhook');
if (participatingAs === "moderator" && !outgoing) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: shouldn't need any check against "Unknown" ?

},
],
};
} else {
throw new Error('This webhook is neither from Slack nor Discord.');
throw new Error("This webhook is neither from Slack nor Discord.");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add here an error log too

headers: {
'Content-Type': 'application/json',
"Content-Type": "application/json",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding Accept... type header also (to enforce the response type), and consider adding the charset to the content-type

// Let's handle the errors and log them
console.error('Error:', error.message);
// Handle errors and log them
console.error("Error:", error.message);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider adding the entire error instead of just the error.message not to swallow/hide stack and information.
Also, I highly recommend to avoid redundant keyword stacking. .error Error. Rather give some human-readable message here, what kind of error you got and why (context & details)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants