Files
filebrowser/utils/errors/errors.go
T

25 lines
421 B
Go
Raw Normal View History

2016-10-22 12:07:19 +01:00
package errors
2016-06-25 21:57:10 +01:00
import (
"net/http"
"os"
)
2016-10-31 21:26:47 +00:00
// ErrorToHTTPCode converts errors to HTTP Status Code.
2016-10-18 21:30:10 +01:00
func ErrorToHTTPCode(err error, gone bool) int {
2016-06-25 21:57:10 +01:00
switch {
case os.IsPermission(err):
return http.StatusForbidden
case os.IsNotExist(err):
2016-10-18 21:30:10 +01:00
if !gone {
return http.StatusNotFound
}
return http.StatusGone
2016-06-25 21:57:10 +01:00
case os.IsExist(err):
return http.StatusGone
default:
return http.StatusInternalServerError
}
}