-
Notifications
You must be signed in to change notification settings - Fork 919
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(share/p2p/shrex): add recovery middleware to shrex-nd and shrex-…
…eds servers (#3328) Add recovery middleware to shrex-eds and shrex-nd server implementation
- Loading branch information
Showing
3 changed files
with
29 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package p2p | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/libp2p/go-libp2p/core/network" | ||
) | ||
|
||
// RecoveryMiddleware is a middleware that recovers from panics in the handler. | ||
func RecoveryMiddleware(handler network.StreamHandler) network.StreamHandler { | ||
return func(stream network.Stream) { | ||
defer func() { | ||
r := recover() | ||
if r != nil { | ||
err := fmt.Errorf("PANIC while handling request: %s", r) | ||
log.Error(err) | ||
} | ||
}() | ||
handler(stream) | ||
} | ||
} |
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