filebrowser/utils/errors.go

24 lines
364 B
Go
Raw Normal View History

2016-10-18 20:30:10 +00:00
package utils
2016-06-25 20:57:10 +00:00
import (
"net/http"
"os"
)
2016-10-18 20:30:10 +00:00
func ErrorToHTTPCode(err error, gone bool) int {
2016-06-25 20:57:10 +00:00
switch {
case os.IsPermission(err):
return http.StatusForbidden
case os.IsNotExist(err):
2016-10-18 20:30:10 +00:00
if !gone {
return http.StatusNotFound
}
return http.StatusGone
2016-06-25 20:57:10 +00:00
case os.IsExist(err):
return http.StatusGone
default:
return http.StatusInternalServerError
}
}