Skip to content

Commit

Permalink
feat: add GetDetails method for tiny_errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Moranilt committed Mar 6, 2024
1 parent ebe3f9c commit 21915a3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tiny_errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type ErrorHandler interface {
GetHTTPMessage() string
GetCode() int
GetMessage() string
GetDetails() map[string]any
}

// PropertySetter defines methods to set error properties like message,
Expand Down Expand Up @@ -99,6 +100,11 @@ func (e *Error) GetHTTPMessage() string {
return e.httpMessage
}

// Returns the details map of the Error.
func (e *Error) GetDetails() map[string]any {
return e.Details
}

// Sets the code field of the Error.
func (e *Error) SetCode(code int) {
e.Code = code
Expand Down
6 changes: 6 additions & 0 deletions tiny_errors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ func TestError_SetCode(t *testing.T) {
assert.Equal(t, 500, err.Code)
}

func TestError_GetDetails(t *testing.T) {
err := New(1, Detail("name", "John"))

assert.Equal(t, map[string]any{"name": "John"}, err.GetDetails())
}

func BenchmarkHandlerError_GoJSON(b *testing.B) {
for i := 0; i < b.N; i++ {
err := &Error{
Expand Down

0 comments on commit 21915a3

Please sign in to comment.