diff --git a/error.go b/error.go index e577a1c..4645d41 100644 --- a/error.go +++ b/error.go @@ -58,3 +58,11 @@ func ErrorMessage(err error) string { } return INTERNAL_ERROR_MESSAGE } + +// Errorf is a helper function to return an Error with a given code and format +func Errorf(code string, format string, args ...interface{}) *Error { + return &Error{ + Code: code, + Message: fmt.Sprintf(format, args...), + } +} diff --git a/error_test.go b/error_test.go index ec1deac..20917c0 100644 --- a/error_test.go +++ b/error_test.go @@ -49,7 +49,7 @@ func TestErrorMessage(t *testing.T) { }) t.Run("should return application error message", func(t *testing.T) { - e := &Error{Message: "my_message"} + e := Errorf(ENOTFOUND, "Entity %s not found", "dirp") got := ErrorMessage(e) AssertErrorString(t, got, e.Message)