(t *testing.T)
| 414 | } |
| 415 | |
| 416 | func TestErrorHandlingWithInternalHttpError(t *testing.T) { |
| 417 | t.Parallel() |
| 418 | |
| 419 | logBuffer := logtest.NewDefaultTestLogBuffer() |
| 420 | logger, err := log.NewDefaultLoggerFactory().Create( |
| 421 | log.WithOutputWriter(logBuffer), |
| 422 | ) |
| 423 | assert.NoError(t, err) |
| 424 | |
| 425 | httpServer := echo.New() |
| 426 | httpServer.Logger = httpserver.NewEchoLogger(logger) |
| 427 | httpServer.HTTPErrorHandler = httpserver.NewJsonErrorHandler(false, false).Handle() |
| 428 | |
| 429 | httpServer.GET("/test", func(c echo.Context) error { |
| 430 | internalError := echo.NewHTTPError(http.StatusInternalServerError, "internal error") |
| 431 | |
| 432 | return &echo.HTTPError{ |
| 433 | Code: http.StatusInternalServerError, |
| 434 | Message: internalError.Error(), |
| 435 | Internal: internalError, |
| 436 | } |
| 437 | }) |
| 438 | |
| 439 | req := httptest.NewRequest(http.MethodGet, "/test", nil) |
| 440 | req = req.WithContext(logger.WithContext(context.Background())) |
| 441 | rec := httptest.NewRecorder() |
| 442 | httpServer.ServeHTTP(rec, req) |
| 443 | |
| 444 | assert.Equal(t, http.StatusInternalServerError, rec.Code) |
| 445 | assert.Contains(t, rec.Body.String(), `{"message":"internal error"}`) |
| 446 | |
| 447 | logtest.AssertContainLogRecord(t, logBuffer, map[string]interface{}{ |
| 448 | "level": "error", |
| 449 | "error": "internal error", |
| 450 | "message": "error handler", |
| 451 | }) |
| 452 | } |
| 453 | |
| 454 | func TestErrorHandlingWithInternalHttpErrorWithStack(t *testing.T) { |
| 455 | t.Parallel() |
nothing calls this directly
no test coverage detected