mirror of
https://github.com/rancher/norman.git
synced 2025-08-19 07:46:59 +00:00
Return 404 when no store is configured (not 200)
This commit is contained in:
parent
c814e62e43
commit
45214c311d
@ -3,6 +3,7 @@ package handler
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/rancher/norman/httperror"
|
||||||
"github.com/rancher/norman/types"
|
"github.com/rancher/norman/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -15,12 +16,14 @@ func CreateHandler(apiContext *types.APIContext, next types.RequestHandler) erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
store := apiContext.Schema.Store
|
store := apiContext.Schema.Store
|
||||||
if store != nil {
|
if store == nil {
|
||||||
|
return httperror.NewAPIError(httperror.NotFound, "no store found")
|
||||||
|
}
|
||||||
|
|
||||||
data, err = store.Create(apiContext, apiContext.Schema, data)
|
data, err = store.Create(apiContext, apiContext.Schema, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
apiContext.WriteResponse(http.StatusCreated, data)
|
apiContext.WriteResponse(http.StatusCreated, data)
|
||||||
return nil
|
return nil
|
||||||
|
@ -3,14 +3,14 @@ package handler
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/rancher/norman/httperror"
|
||||||
"github.com/rancher/norman/types"
|
"github.com/rancher/norman/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DeleteHandler(request *types.APIContext, next types.RequestHandler) error {
|
func DeleteHandler(request *types.APIContext, next types.RequestHandler) error {
|
||||||
store := request.Schema.Store
|
store := request.Schema.Store
|
||||||
if store == nil {
|
if store == nil {
|
||||||
request.WriteResponse(http.StatusNoContent, nil)
|
return httperror.NewAPIError(httperror.NotFound, "no store found")
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
obj, err := store.Delete(request, request.Schema, request.ID)
|
obj, err := store.Delete(request, request.Schema, request.ID)
|
||||||
|
@ -3,6 +3,7 @@ package handler
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/rancher/norman/httperror"
|
||||||
"github.com/rancher/norman/parse"
|
"github.com/rancher/norman/parse"
|
||||||
"github.com/rancher/norman/types"
|
"github.com/rancher/norman/types"
|
||||||
)
|
)
|
||||||
@ -15,7 +16,7 @@ func ListHandler(request *types.APIContext, next types.RequestHandler) error {
|
|||||||
|
|
||||||
store := request.Schema.Store
|
store := request.Schema.Store
|
||||||
if store == nil {
|
if store == nil {
|
||||||
return nil
|
return httperror.NewAPIError(httperror.NotFound, "no store found")
|
||||||
}
|
}
|
||||||
|
|
||||||
if request.ID == "" {
|
if request.ID == "" {
|
||||||
|
@ -3,6 +3,7 @@ package handler
|
|||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/rancher/norman/httperror"
|
||||||
"github.com/rancher/norman/types"
|
"github.com/rancher/norman/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -13,12 +14,14 @@ func UpdateHandler(apiContext *types.APIContext, next types.RequestHandler) erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
store := apiContext.Schema.Store
|
store := apiContext.Schema.Store
|
||||||
if store != nil {
|
if store == nil {
|
||||||
|
return httperror.NewAPIError(httperror.NotFound, "no store found")
|
||||||
|
}
|
||||||
|
|
||||||
data, err = store.Update(apiContext, apiContext.Schema, data, apiContext.ID)
|
data, err = store.Update(apiContext, apiContext.Schema, data, apiContext.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
apiContext.WriteResponse(http.StatusOK, data)
|
apiContext.WriteResponse(http.StatusOK, data)
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user