Skip to content

Commit

Permalink
feat(errors): added New (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
flc1125 authored Oct 13, 2023
1 parent 95d6e12 commit 32b449c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ var (
IsClientClosed = errors.IsClientClosed
)

func New(code int, message string) *errors.Error {
return errors.New(code, http.StatusText(code), message)
}

func BadRequest(message string) *errors.Error {
return errors.BadRequest(http.StatusText(http.StatusBadRequest), message)
}
Expand Down
6 changes: 6 additions & 0 deletions errors/errors_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package errors

import (
"net/http"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -18,3 +19,8 @@ func TestErrors(t *testing.T) {
assert.True(t, IsClientClosed(ClientClosed("ClientClosed")))
assert.True(t, IsClientClosed(ClientClosed("ClientClosed")))
}

func TestErrors_New(t *testing.T) {
assert.True(t, IsForbidden(New(http.StatusForbidden, "Forbidden")))
assert.Equal(t, New(http.StatusForbidden, "Forbidden"), Forbidden("Forbidden"))
}

0 comments on commit 32b449c

Please sign in to comment.