Skip to content

Commit

Permalink
All echo.NewHTTPErrors have a SetInternal attached to them (#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
javorszky committed Mar 24, 2023
1 parent 86a9b46 commit b56c021
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
14 changes: 8 additions & 6 deletions e2core/server/handlers.go
@@ -1,9 +1,11 @@
package server

import (
"fmt"
"net/http"

"github.com/labstack/echo/v4"
"github.com/pkg/errors"
"github.com/rs/zerolog"

"github.com/suborbital/e2core/e2core/sequence"
Expand All @@ -26,7 +28,7 @@ func (s *Server) executePluginByNameHandler() echo.HandlerFunc {
mod := s.syncer.GetModuleByName(ident, namespace, name)
if mod == nil {
ll.Error().Msg("syncer did not find module by these details")
return echo.NewHTTPError(http.StatusNotFound, "module not found")
return echo.NewHTTPError(http.StatusNotFound, "module not found").SetInternal(fmt.Errorf("no module with %s/%s/%s", ident, namespace, name))
}

req, err := request.FromEchoContext(c)
Expand All @@ -48,7 +50,7 @@ func (s *Server) executePluginByNameHandler() echo.HandlerFunc {
// a sequence executes the handler's steps and manages its state.
seq, err := sequence.New(steps, req)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "failed to handle request")
return echo.NewHTTPError(http.StatusInternalServerError, "failed to handle request").SetInternal(err)
}

if err := s.dispatcher.Execute(seq); err != nil {
Expand Down Expand Up @@ -82,7 +84,7 @@ func (s *Server) executePluginByRefHandler(l zerolog.Logger) echo.HandlerFunc {

mod := s.syncer.GetModuleByRef(ref)
if mod == nil {
return echo.NewHTTPError(http.StatusNotFound, "module not found")
return echo.NewHTTPError(http.StatusNotFound, "module not found").SetInternal(fmt.Errorf("no module by ref %s", ref))
}

ll.Debug().Str("fqmn", mod.FQMN).Msg("found module by ref")
Expand All @@ -102,7 +104,7 @@ func (s *Server) executePluginByRefHandler(l zerolog.Logger) echo.HandlerFunc {
// a sequence executes the handler's steps and manages its state.
seq, err := sequence.New(steps, req)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "failed to handle request")
return echo.NewHTTPError(http.StatusInternalServerError, "failed to handle request").SetInternal(err)
}

if err := s.dispatcher.Execute(seq); err != nil {
Expand Down Expand Up @@ -136,7 +138,7 @@ func (s *Server) executeWorkflowHandler() echo.HandlerFunc {

tnt := s.syncer.TenantOverview(ident)
if tnt == nil {
return echo.NewHTTPError(http.StatusNotFound, "not found")
return echo.NewHTTPError(http.StatusNotFound, "not found").SetInternal(fmt.Errorf("no tenant with ident %s", ident))
}

namespaces := []tenant.NamespaceConfig{tnt.Config.DefaultNamespace}
Expand Down Expand Up @@ -166,7 +168,7 @@ func (s *Server) executeWorkflowHandler() echo.HandlerFunc {
}

if workflow == nil {
return echo.NewHTTPError(http.StatusNotFound, "not found")
return echo.NewHTTPError(http.StatusNotFound, "not found").SetInternal(errors.New("workflow was nil"))
}

req, err := request.FromEchoContext(c)
Expand Down
4 changes: 2 additions & 2 deletions e2core/sourceserver/server.go
Expand Up @@ -156,9 +156,9 @@ func (es *SystemSourceRouter) GetModuleHandler() echo.HandlerFunc {
es.logger.Err(err).Msg("es.source.GetModule")

if errors.Is(err, system.ErrModuleNotFound) {
return echo.NewHTTPError(http.StatusNotFound)
return echo.NewHTTPError(http.StatusNotFound).SetInternal(err)
} else if errors.Is(err, system.ErrAuthenticationFailed) {
return echo.NewHTTPError(http.StatusUnauthorized)
return echo.NewHTTPError(http.StatusUnauthorized).SetInternal(err)
}

return echo.NewHTTPError(http.StatusInternalServerError).SetInternal(errors.Wrap(err, "es.source.GetModule"))
Expand Down

0 comments on commit b56c021

Please sign in to comment.