autoresearch iter 3: share upload-record error mapping via filesrv helper

ServeFileByID and DownloadFile duplicated the lookup failure mapping and
each used an unchecked *strconv.NumError assertion that cannot match a
wrapped error. One helper now classifies 404 vs 400 via errors.As; each
endpoint keeps its own fallback for unclassified failures. ErrInvalidUploadID
became unused once both sites report ErrInvalidFileID for a malformed ID.
This commit is contained in:
ryan
2026-08-29 08:02:42 +08:00
parent 4e6209bf61
commit 686e3ef5a6
3 changed files with 19 additions and 13 deletions
@@ -169,12 +169,7 @@ func UploadFile(c *gin.Context) {
func DownloadFile(c *gin.Context) {
upload, err := filesrv.GetUploadRecordByID(c)
if err != nil {
if isRecordNotFound(err) {
response.AbortNotFound(c, shared.ErrFileRecordNotFound)
return
}
if _, ok := err.(*strconv.NumError); ok {
response.AbortBadRequest(c, shared.ErrInvalidFileID)
if filesrv.AbortUploadRecordError(c, err) {
return
}
response.AbortBadRequest(c, shared.ErrQueryUploadRecordFailed)