mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-05 15:26:36 +08:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user