httperrors: fix passing "params" argument

This commit is contained in:
Yousong Zhou
2020-03-23 16:31:45 +08:00
parent 1d5d2276d6
commit a6b8477785
2 changed files with 28 additions and 2 deletions
+2 -2
View File
@@ -197,9 +197,9 @@ func NewClientError(msg string, params ...interface{}) *httputils.JSONClientErro
}
func NewUnclassifiedError(msg string, params ...interface{}) *httputils.JSONClientError {
return httputils.NewJsonClientError(httpErrorCode[errors.ErrUnclassified], string(errors.ErrUnclassified), msg, params)
return httputils.NewJsonClientError(httpErrorCode[errors.ErrUnclassified], string(errors.ErrUnclassified), msg, params...)
}
func NewTooLargeEntityError(msg string, params ...interface{}) *httputils.JSONClientError {
return httputils.NewJsonClientError(httpErrorCode[ErrTooLarge], string(ErrTooLarge), msg, params)
return httputils.NewJsonClientError(httpErrorCode[ErrTooLarge], string(ErrTooLarge), msg, params...)
}
+26
View File
@@ -0,0 +1,26 @@
package httperrors
import (
"fmt"
"strings"
"testing"
)
func TestGeneralError(t *testing.T) {
t.Run("unclassified", func(t *testing.T) {
t.Run("no fmt", func(t *testing.T) {
err := fmt.Errorf("i am an unclassified error")
jce := NewGeneralError(err)
if strings.Contains(jce.Details, "%!(EXTRA") {
t.Errorf("bad error formating: %v", jce)
}
})
t.Run("fmt", func(t *testing.T) {
err := fmt.Errorf("i am error with plain %%s")
jce := NewGeneralError(err)
if strings.Contains(jce.Details, "%!(EXTRA") {
t.Errorf("bad error formating: %v", jce)
}
})
})
}