worker: Use Recover middleware to handle panics

recover from panics such as out-of-bounds array access & nil
pointer access, print a stack trace and return 5xx error
This commit is contained in:
Diaa Sami 2021-10-05 10:24:02 +02:00 committed by Sanne Raymaekers
parent 22f151df68
commit 12ca5325d6

View file

@ -16,6 +16,7 @@ import (
"github.com/google/uuid"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/sirupsen/logrus"
"github.com/osbuild/osbuild-composer/internal/common"
@ -57,6 +58,7 @@ func (s *Server) Handler() http.Handler {
// log errors returned from handlers
e.HTTPErrorHandler = api.HTTPErrorHandler
e.Use(middleware.Recover())
e.Pre(common.OperationIDMiddleware)
handler := apiHandlers{
server: s,