-
Notifications
You must be signed in to change notification settings - Fork 242
Fix: Provide clear error when filename is missing on /data endpoint (Fixes #220) #1705
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
base: main
Are you sure you want to change the base?
Fix: Provide clear error when filename is missing on /data endpoint (Fixes #220) #1705
Conversation
hyperledger#1528) Signed-off-by: Deekshit S <deekshit1403@gmail.com>
hyperledger#220) Signed-off-by: Deekshit S <deekshit1403@gmail.com>
6cd4c37 to
4cc3525
Compare
EnriqueL8
left a comment
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.
Thanks @Deekshit014 for the PR - a few comments and changes needed. Would be great to add a test for the new validation
| @@ -0,0 +1,7 @@ | |||
| { | |||
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.
Why is this needed?
| @@ -0,0 +1,4 @@ | |||
| info: | |||
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.
ditto
| // Check for file upload | ||
| if r.Part == nil || r.Part.FileName() == "" { | ||
| return nil, i18n.NewError(r.Req.Context(), coremsgs.MsgMissingFileUpload) | ||
| } |
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.
For clarity this is what changed
| // @Summary Update an identity | ||
| // @ID patchUpdateIdentity | ||
| // @Tags identities | ||
| // @Accept json | ||
| // @Produce json | ||
| // @Param iid path string true "Identity ID" <-- THE CRITICAL FIX | ||
| // @Param body body core.IdentityUpdateDTO true "Identity update details" | ||
| // @Success 202 {object} core.Identity | ||
| // @Router /identities/{iid} [patch] |
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.
These remind me of sprint boot tags, where did you get these from?
| "github.com/hyperledger/firefly/pkg/core" | ||
| ) | ||
|
|
||
| // @Summary Get identity by ID |
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.
ditto it would be significant decisions to bring in a DSL for describing APIs since we already have within ffapi the ability to describe the API and transform it to an OpenAPI document
Proposed changes
Please include a summary of the changes here and why we need those changes. And also let us know which issue is fixed.
This Pull Request resolves Issue #220.
The issue was that when a developer attempted to upload data to the
/dataendpoint using themultipart/form-datacontent type but omitted the requiredfilename, the API returned a generic or confusing validation error.The change introduces an explicit check at the start of the form upload handler to ensure the file part and filename are present, returning a clear, user-friendly error message (
MsgFilenameRequired) instead of letting the request fail later with a misleading error.Fixes #220
Types of changes
Please make sure to follow these points
Screenshots (If Applicable)
Other Information
The fix was applied in
internal/apiserver/route_post_data.gowithin theCoreFormUploadHandler. I inserted the check forr.Part == nil || r.Part.FileName == ""at the start of the handler to ensure the error is returned at the point of validation, leading to better developer experience.