Skip to content

Commit

Permalink
Fix file err NotExist returning 500 instead of 404 (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
QuintenQVD0 authored Dec 12, 2024
1 parent c2d1b27 commit 11d6284
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion router/middleware/request_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (re *RequestError) asFilesystemError() (int, string) {
return 0, ""
}
if filesystem.IsErrorCode(err, filesystem.ErrNotExist) ||
filesystem.IsErrorCode(err, filesystem.ErrCodePathResolution) ||
filesystem.IsErrorCode(err, filesystem.ErrCodePathResolution) || strings.Contains(err.Error(), "file does not exist") ||
strings.Contains(err.Error(), "resolves to a location outside the server root") {
return http.StatusNotFound, "The requested resources was not found on the system."
}
Expand Down
9 changes: 7 additions & 2 deletions router/router_server_files.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@ func getServerFileContents(c *gin.Context) {
}
f, st, err := s.Filesystem().File(p)
if err != nil {
middleware.CaptureAndAbort(c, err)
if strings.Contains(err.Error(), "file does not exist") {
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{
"error": "The requested resources was not found on the system.",
"request_id": c.Writer.Header().Get("X-Request-Id")})
} else {
middleware.CaptureAndAbort(c, err)
}
return
}
defer f.Close()
Expand Down Expand Up @@ -89,7 +95,6 @@ func getServerListDirectory(c *gin.Context) {
}
}


type renameFile struct {
To string `json:"to"`
From string `json:"from"`
Expand Down

0 comments on commit 11d6284

Please sign in to comment.