Skip to content

Conversation

RoshniNaveenaS
Copy link
Contributor

@RoshniNaveenaS RoshniNaveenaS commented Jul 24, 2025

This PR addresses issue #227 with better error handling, especially for non-draft attachment uploads:
• Added robust error handling and logging in attachment creation and upload handlers.
• Improved validation and rejection of invalid requests to prevent unhandled exceptions.
• Enhanced overall stability to avoid server crashes during file upload operations.

Also the documentation update is also covered as part of this PR

These changes improve reliability and make debugging easier.

…t operations

	Wrapped nonDraftHandler(), put(), and updateContentHandler() in try/catch blocks to ensure proper error propagation using req.error(...).
	•	Ensured await super.put(...) is followed by error-safe logic in put().
	•	Invoked scanRequest() asynchronously with catch() to avoid crashing on malware scanner failures.
	•	Prevented unhandled exceptions during file uploads and metadata updates in non-draft flow.
…raftUpload

- Wrap srv.before("NEW"/"CREATE") handler with try/catch to log errors and reject on failure during attachment initialization
- Update nonDraftUpload function to handle errors gracefully, log failures, and reject to prevent unhandled exceptions

Improves robustness by preventing crashes due to unhandled errors in attachment upload lifecycle.
Copy link

@maheshsooryambylu maheshsooryambylu left a comment

Choose a reason for hiding this comment

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

Looks good. Overall I have 2 questions on the code.

Choose a reason for hiding this comment

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

How the non-draft and draft scenarios be distinguishable from the usage perspective?

try {
if (req?.content?.url?.endsWith("/content")) {
const attachmentID = req.content.url.match(attachmentIDRegex)[1];
await AttachmentsSrv.nonDraftHandler(target, { ID: attachmentID, content: req.content });

Choose a reason for hiding this comment

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

Doesn't the line 117 need to be executed only after the attachmentID is obtained ? I mean would there be a situation when AttachmentsSrv.nonDraftHandler is called when url.match is asynchronously being executed ?

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.

2 participants