mirror of
https://github.com/hashicorp/vault.git
synced 2025-11-28 22:21:30 +01:00
ErrUserInput --> StatusBadRequest
This commit is contained in:
parent
9da292932e
commit
edfba16e95
@ -147,7 +147,7 @@ func respondErrorStatus(w http.ResponseWriter, err error) {
|
|||||||
status := http.StatusInternalServerError
|
status := http.StatusInternalServerError
|
||||||
switch {
|
switch {
|
||||||
// Keep adding more error types here to appropriate the status codes
|
// Keep adding more error types here to appropriate the status codes
|
||||||
case errwrap.ContainsType(err, new(vault.ErrUserInput)):
|
case errwrap.ContainsType(err, new(vault.StatusBadRequest)):
|
||||||
status = http.StatusBadRequest
|
status = http.StatusBadRequest
|
||||||
}
|
}
|
||||||
respondError(w, status, err)
|
respondError(w, status, err)
|
||||||
|
|||||||
@ -3,12 +3,12 @@ package vault
|
|||||||
// Struct to identify user input errors.
|
// Struct to identify user input errors.
|
||||||
// This is helpful in responding the appropriate status codes to clients
|
// This is helpful in responding the appropriate status codes to clients
|
||||||
// from the HTTP endpoints.
|
// from the HTTP endpoints.
|
||||||
type ErrUserInput struct {
|
type StatusBadRequest struct {
|
||||||
Message string
|
Message string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implementing error interface
|
// Implementing error interface
|
||||||
func (e *ErrUserInput) Error() string {
|
func (e *StatusBadRequest) Error() string {
|
||||||
return e.Message
|
return e.Message
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -16,13 +16,13 @@ func (e *ErrUserInput) Error() string {
|
|||||||
// the token accessor an the given path
|
// the token accessor an the given path
|
||||||
func (c *Core) CapabilitiesAccessor(accessorID, path string) ([]string, error) {
|
func (c *Core) CapabilitiesAccessor(accessorID, path string) ([]string, error) {
|
||||||
if path == "" {
|
if path == "" {
|
||||||
return nil, &ErrUserInput{
|
return nil, &StatusBadRequest{
|
||||||
Message: "missing path",
|
Message: "missing path",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if accessorID == "" {
|
if accessorID == "" {
|
||||||
return nil, &ErrUserInput{
|
return nil, &StatusBadRequest{
|
||||||
Message: "missing accessor_id",
|
Message: "missing accessor_id",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -38,13 +38,13 @@ func (c *Core) CapabilitiesAccessor(accessorID, path string) ([]string, error) {
|
|||||||
// Capabilities is used to fetch the capabilities of the given token on the given path
|
// Capabilities is used to fetch the capabilities of the given token on the given path
|
||||||
func (c *Core) Capabilities(token, path string) ([]string, error) {
|
func (c *Core) Capabilities(token, path string) ([]string, error) {
|
||||||
if path == "" {
|
if path == "" {
|
||||||
return nil, &ErrUserInput{
|
return nil, &StatusBadRequest{
|
||||||
Message: "missing path",
|
Message: "missing path",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if token == "" {
|
if token == "" {
|
||||||
return nil, &ErrUserInput{
|
return nil, &StatusBadRequest{
|
||||||
Message: "missing token",
|
Message: "missing token",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -54,7 +54,7 @@ func (c *Core) Capabilities(token, path string) ([]string, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if te == nil {
|
if te == nil {
|
||||||
return nil, &ErrUserInput{
|
return nil, &StatusBadRequest{
|
||||||
Message: "invalid token",
|
Message: "invalid token",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -606,7 +606,7 @@ func (ts *TokenStore) lookupByAccessorID(accessorID string) (string, error) {
|
|||||||
return "", fmt.Errorf("failed to read index using accessor ID: %s", err)
|
return "", fmt.Errorf("failed to read index using accessor ID: %s", err)
|
||||||
}
|
}
|
||||||
if entry == nil {
|
if entry == nil {
|
||||||
return "", &ErrUserInput{
|
return "", &StatusBadRequest{
|
||||||
Message: "invalid accessor ID",
|
Message: "invalid accessor ID",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user