Merge pull request #5581 from yousong/bugfix/yousong-httperrors

httperrors: fix passing "params" argument
This commit is contained in:
Zexi Li
2020-03-23 21:13:59 +08:00
committed by GitHub
3 changed files with 29 additions and 3 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)
}
})
})
}
+1 -1
View File
@@ -94,7 +94,7 @@ func NewSSHtoolSolCommand(ctx context.Context, userCred mcclient.TokenCredential
}
conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%d", ip, port), time.Second*2)
if err != nil {
return nil, fmt.Errorf("IPAddress %s:%d not accessable", ip, port)
return nil, fmt.Errorf("IPAddress %s:%d not accessible", ip, port)
}
defer conn.Close()