-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull request #70: Fixed the LogErrorFuncWithRequestInfo to return the…
… error in order to pass the error to the global error handling mechanism Merge in AW/go-starter from ek/panic-recover-error-handler-func to master * commit '12d9c2818eabe998f881848f918bd73747dbc4d3': added test for recover log error func Fixed the LogErrorFuncWithRequestInfo to return the error in order to pass the error to the global error handling mechanism
- Loading branch information
Showing
5 changed files
with
47 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package middleware_test | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"testing" | ||
|
||
"allaboutapps.dev/aw/go-starter/internal/api" | ||
"allaboutapps.dev/aw/go-starter/internal/api/middleware" | ||
"allaboutapps.dev/aw/go-starter/internal/test" | ||
"github.com/labstack/echo/v4" | ||
echoMiddleware "github.com/labstack/echo/v4/middleware" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestLogErrorFuncWithRequestInfo(t *testing.T) { | ||
test.WithTestServer(t, func(s *api.Server) { | ||
path := "/testing-e87bc94c-2d1f-4342-9ec2-f158c63ac6da" | ||
|
||
s.Echo.Use(echoMiddleware.RecoverWithConfig(echoMiddleware.RecoverConfig{ | ||
LogErrorFunc: middleware.LogErrorFuncWithRequestInfo, | ||
})) | ||
|
||
s.Echo.POST(path, func(c echo.Context) error { | ||
|
||
var val *int | ||
fmt.Println(*val) | ||
|
||
return c.NoContent(http.StatusNoContent) | ||
}) | ||
|
||
res := test.PerformRequest(t, s, "POST", path, nil, nil) | ||
require.Equal(t, http.StatusInternalServerError, res.Result().StatusCode) | ||
|
||
body, err := io.ReadAll(res.Body) | ||
require.NoError(t, err) | ||
|
||
test.Snapshoter.SaveString(t, string(body)) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"status":500,"title":"Internal Server Error","type":"generic"} |