1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-08 17:55:59 +01:00

Improve HTTP error for unknown permissions.

This commit is contained in:
Juliusz Chroboczek 2024-11-08 17:07:11 +01:00
parent 75d6d87c23
commit a73c42ce08
2 changed files with 7 additions and 2 deletions

View file

@ -17,6 +17,7 @@ import (
var ErrTagMismatch = errors.New("tag mismatch")
var ErrDescriptionsNotWritable = &NotAuthorisedError{}
var ErrUnknownPermission = errors.New("unknown permission")
type Permissions struct {
// non-empty for a named permissions set
@ -37,7 +38,7 @@ var permissionsMap = map[string][]string{
func NewPermissions(name string) (Permissions, error) {
_, ok := permissionsMap[name]
if !ok {
return Permissions{}, errors.New("unknown permission")
return Permissions{}, ErrUnknownPermission
}
return Permissions{
name: name,
@ -112,7 +113,7 @@ func (p *Permissions) UnmarshalJSON(b []byte) error {
if err == nil {
_, ok := permissionsMap[s]
if !ok {
return errors.New("Unknown permission " + s)
return ErrUnknownPermission
}
*p = Permissions{
name: s,

View file

@ -124,6 +124,10 @@ func httpError(w http.ResponseWriter, err error) {
notFound(w)
return
}
if errors.Is(err, group.ErrUnknownPermission) {
http.Error(w, "unknown permission", http.StatusBadRequest)
return
}
var autherr *group.NotAuthorisedError
if errors.As(err, &autherr) {
log.Printf("HTTP server error: %v", err)