Skip to content

Commit

Permalink
feat(recovery): Add recovery (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
flc1125 authored Oct 31, 2023
1 parent 4dceb84 commit 2d525ad
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions recovery/recovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func New(opts ...Option) *Recovery {
}
}

func (r *Recovery) Wrap(f func() error) error {
func (r *Recovery) Wrap(f func()) {
defer func() {
if err := recover(); err != nil {
if r.opt.handler != nil {
Expand All @@ -43,5 +43,5 @@ func (r *Recovery) Wrap(f func() error) error {
}
}()

return f()
f()
}
10 changes: 5 additions & 5 deletions recovery/recovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ import (
)

func TestRecovery_Wrap(t *testing.T) {
fn := func() error {
fn := func() {
panic("test")

return nil
}

// default
r := New()
assert.Panics(t, func() {
_ = r.Wrap(fn)
r.Wrap(fn)
})

// with handler
r = New(WithHandler(func(err interface{}) {
assert.Equal(t, "test", err)
}))

assert.NoError(t, r.Wrap(fn))
assert.NotPanics(t, func() {
r.Wrap(fn)
})
}

0 comments on commit 2d525ad

Please sign in to comment.