Skip to content

Commit

Permalink
feature WS-648: Updated the default write controller to handle unauth…
Browse files Browse the repository at this point in the history
…orized errors
  • Loading branch information
IshikaGopie committed Mar 26, 2024
1 parent 54d4173 commit 82a6786
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions controllers/rest/default_controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"time"
)

//DefaultWriteController handles the write operations (create, update, delete)
// DefaultWriteController handles the write operations (create, update, delete)
func DefaultWriteController(api Container, commandDispatcher model.CommandDispatcher, entityRepository model.EntityRepository, pathMap map[string]*openapi3.PathItem, operation map[string]*openapi3.Operation) echo.HandlerFunc {
var commandName string
var err error
Expand Down Expand Up @@ -87,6 +87,8 @@ func DefaultWriteController(api Container, commandDispatcher model.CommandDispat
if err != nil {
if derr, ok := err.(*model.DomainError); ok && derr.Code == 400 {
return ctxt.JSON(http.StatusBadRequest, derr)
} else if derr, ok = err.(*model.DomainError); ok && derr.Code == 401 {
return ctxt.JSON(http.StatusUnauthorized, derr)
}
return err
}
Expand All @@ -111,7 +113,7 @@ func DefaultWriteController(api Container, commandDispatcher model.CommandDispat
}
}

//DefaultReadController handles the read operations viewing a specific item
// DefaultReadController handles the read operations viewing a specific item
func DefaultReadController(api Container, commandDispatcher model.CommandDispatcher, entityRepository model.EntityRepository, pathMap map[string]*openapi3.PathItem, operationMap map[string]*openapi3.Operation) echo.HandlerFunc {
logger, err := api.GetLog("Default")
if err != nil {
Expand Down Expand Up @@ -247,7 +249,7 @@ func DefaultReadController(api Container, commandDispatcher model.CommandDispatc
}
}

//DefaultListController handles the read operations viewing a list of items
// DefaultListController handles the read operations viewing a list of items
func DefaultListController(api Container, commandDispatcher model.CommandDispatcher, entityRepository model.EntityRepository, pathMap map[string]*openapi3.PathItem, operationMap map[string]*openapi3.Operation) echo.HandlerFunc {
return func(ctxt echo.Context) error {
var filterOptions map[string]interface{}
Expand Down

0 comments on commit 82a6786

Please sign in to comment.