-
Notifications
You must be signed in to change notification settings - Fork 8
Fix(attachments): Improve Error Handling in Upload Lifecycle and Non-draft Upload Flow #228
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
Open
RoshniNaveenaS
wants to merge
6
commits into
main
Choose a base branch
from
non-draft-doc-and-error-fixes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4f58573
docs(README): add non-draft upload example using .http file
RoshniNaveenaS 8ddd8ba
fix(aws-s3.js): improve error handling for non-draft and updateConten…
RoshniNaveenaS b3cbf1f
refactor(aws-s3): replace console.error with cds.log().error for cons…
RoshniNaveenaS c72fdb2
feat(basic.js): add robust error handling and non-blocking malware sc…
RoshniNaveenaS 74f3465
fix(attachments): add error handling for PUT before handlers and nonD…
RoshniNaveenaS 485c63f
Fix lint issues in aws-s3.js and improve error context propagation
RoshniNaveenaS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,15 +56,20 @@ cds.once("served", async function registerPluginHandlers () { | |
|
||
const op = isDraft ? "NEW" : "CREATE"; | ||
srv.before(op, putTarget, (req) => { | ||
req.data.url = cds.utils.uuid() | ||
const isMultitenacyEnabled = !!cds.env.requires.multitenancy; | ||
const objectStoreKind = cds.env.requires?.attachments?.objectStore?.kind; | ||
if (isMultitenacyEnabled && objectStoreKind === "shared") { | ||
req.data.url = `${req.tenant}_${req.data.url}`; | ||
try { | ||
req.data.url = cds.utils.uuid() | ||
const isMultitenacyEnabled = !!cds.env.requires.multitenancy; | ||
const objectStoreKind = cds.env.requires?.attachments?.objectStore?.kind; | ||
if (isMultitenacyEnabled && objectStoreKind === "shared") { | ||
req.data.url = `${req.tenant}_${req.data.url}`; | ||
} | ||
req.data.ID = cds.utils.uuid() | ||
let ext = extname(req.data.filename).toLowerCase().slice(1) | ||
req.data.mimeType = Ext2MimeTyes[ext] || "application/octet-stream" | ||
} catch (err) { | ||
LOG.error('[PUT_BEFORE_ERROR]', err); | ||
req.reject(500, 'Attachment initialization failed.') | ||
} | ||
req.data.ID = cds.utils.uuid() | ||
let ext = extname(req.data.filename).toLowerCase().slice(1) | ||
req.data.mimeType = Ext2MimeTyes[ext] || "application/octet-stream" | ||
}); | ||
|
||
if (isDraft) { | ||
|
@@ -106,11 +111,16 @@ cds.once("served", async function registerPluginHandlers () { | |
} | ||
|
||
async function nonDraftUpload(req, target) { | ||
if (req?.content?.url?.endsWith("/content")) { | ||
const attachmentID = req.content.url.match(attachmentIDRegex)[1]; | ||
AttachmentsSrv.nonDraftHandler(target, { ID: attachmentID, content: req.content }); | ||
} | ||
} | ||
try { | ||
if (req?.content?.url?.endsWith("/content")) { | ||
const attachmentID = req.content.url.match(attachmentIDRegex)[1]; | ||
await AttachmentsSrv.nonDraftHandler(target, { ID: attachmentID, content: req.content }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ? |
||
} | ||
} catch (err) { | ||
LOG.error('[NON_DRAFT_UPLOAD_ERROR]', err); | ||
req.reject(500, 'Non-draft attachment upload failed.'); | ||
} | ||
} | ||
}) | ||
|
||
function validateAttachmentSize (req) { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?