Add helper function to errors

main
Drew Bednar 7 days ago
parent f8ccbe90b4
commit eb2f42d50a

@ -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...),
}
}

@ -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)

Loading…
Cancel
Save