mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
21 lines
362 B
Go
21 lines
362 B
Go
|
package errors
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
"os"
|
||
|
)
|
||
|
|
||
|
// ToHTTPCode gets the respective HTTP code for an error
|
||
|
func ToHTTPCode(err error) int {
|
||
|
switch {
|
||
|
case os.IsPermission(err):
|
||
|
return http.StatusForbidden
|
||
|
case os.IsNotExist(err):
|
||
|
return http.StatusNotFound
|
||
|
case os.IsExist(err):
|
||
|
return http.StatusGone
|
||
|
default:
|
||
|
return http.StatusInternalServerError
|
||
|
}
|
||
|
}
|