mirror of
https://github.com/harness/drone.git
synced 2025-05-06 00:31:34 +08:00

Adds the basic for harness embedded mode: - Harness dedicated router with custom APIHandler - Inline Space Creation - Client for Account/Org/Project - Bootstrap (Allows for automated creation of admin user and gitness service (used for all platform required ops)) - Inline harness service principal creation - Ignore flag for ACL.
52 lines
1.3 KiB
Go
52 lines
1.3 KiB
Go
package usererror
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
|
|
apiauth "github.com/harness/gitness/internal/api/auth"
|
|
"github.com/harness/gitness/internal/store"
|
|
"github.com/harness/gitness/types/check"
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
func Translate(err error) *Error {
|
|
var rError *Error
|
|
switch {
|
|
// api errors
|
|
case errors.As(err, &rError):
|
|
return rError
|
|
|
|
// api auth errors
|
|
case errors.Is(err, apiauth.ErrNotAuthenticated):
|
|
return ErrUnauthorized
|
|
case errors.Is(err, apiauth.ErrNotAuthorized):
|
|
return ErrForbidden
|
|
|
|
// validation errors
|
|
case errors.Is(err, check.ErrAny):
|
|
return New(http.StatusBadRequest, err.Error())
|
|
|
|
// store errors
|
|
case errors.Is(err, store.ErrResourceNotFound):
|
|
return ErrNotFound
|
|
case errors.Is(err, store.ErrDuplicate):
|
|
return ErrDuplicate
|
|
case errors.Is(err, store.ErrPrimaryPathCantBeDeleted):
|
|
return ErrPrimaryPathCantBeDeleted
|
|
case errors.Is(err, store.ErrPathTooLong):
|
|
return ErrPathTooLong
|
|
case errors.Is(err, store.ErrNoChangeInRequestedMove):
|
|
return ErrNoChange
|
|
case errors.Is(err, store.ErrIllegalMoveCyclicHierarchy):
|
|
return ErrCyclicHierarchy
|
|
case errors.Is(err, store.ErrSpaceWithChildsCantBeDeleted):
|
|
return ErrSpaceWithChildsCantBeDeleted
|
|
|
|
// unknown error
|
|
default:
|
|
log.Warn().Msgf("Unable to translate error: %s", err)
|
|
return ErrInternal
|
|
}
|
|
}
|