Skip to content

Commit

Permalink
Check whether is nil before invoking centralized error handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
px3303 authored and aldas committed Apr 15, 2023
1 parent a7802ea commit de1c798
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions middleware/recover.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type (

// LogErrorFunc defines a function for custom logging in the middleware.
// If it's set you don't need to provide LogLevel for config.
// If this function returns nil, the centralized HTTPErrorHandler will not be called.
LogErrorFunc LogErrorFunc

// DisableErrorHandler disables the call to centralized HTTPErrorHandler.
Expand All @@ -49,12 +50,12 @@ type (
var (
// DefaultRecoverConfig is the default Recover middleware config.
DefaultRecoverConfig = RecoverConfig{
Skipper: DefaultSkipper,
StackSize: 4 << 10, // 4 KB
DisableStackAll: false,
DisablePrintStack: false,
LogLevel: 0,
LogErrorFunc: nil,
Skipper: DefaultSkipper,
StackSize: 4 << 10, // 4 KB
DisableStackAll: false,
DisablePrintStack: false,
LogLevel: 0,
LogErrorFunc: nil,
DisableErrorHandler: false,
}
)
Expand Down Expand Up @@ -120,7 +121,7 @@ func RecoverWithConfig(config RecoverConfig) echo.MiddlewareFunc {
}
}

if(!config.DisableErrorHandler) {
if err != nil && !config.DisableErrorHandler {
c.Error(err)
} else {
returnErr = err
Expand Down
2 changes: 1 addition & 1 deletion middleware/request_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func (config RequestLoggerConfig) ToMiddleware() (echo.MiddlewareFunc, error) {
config.BeforeNextFunc(c)
}
err := next(c)
if config.HandleError {
if err != nil && config.HandleError {
c.Error(err)
}

Expand Down

0 comments on commit de1c798

Please sign in to comment.