mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
25 lines
426 B
Go
25 lines
426 B
Go
package filemanager
|
|
|
|
import (
|
|
"net/http"
|
|
"os"
|
|
)
|
|
|
|
// errorToHTTPCode converts errors to HTTP Status Code.
|
|
func errorToHTTPCode(err error, gone bool) int {
|
|
switch {
|
|
case os.IsPermission(err):
|
|
return http.StatusForbidden
|
|
case os.IsNotExist(err):
|
|
if !gone {
|
|
return http.StatusNotFound
|
|
}
|
|
|
|
return http.StatusGone
|
|
case os.IsExist(err):
|
|
return http.StatusGone
|
|
default:
|
|
return http.StatusInternalServerError
|
|
}
|
|
}
|