代码拉取完成,页面将自动刷新
GetBackendWithConfig and make logging configurable per backend
package stripe
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
assert "github.com/stretchr/testify/require"
)
func TestErrorError(t *testing.T) {
err := &Error{Type: "foo", Msg: "bar"}
assert.Equal(t, `{"message":"bar","type":"foo"}`, err.Error())
}
func TestErrorResponse(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Request-Id", "req_123")
w.WriteHeader(http.StatusUnauthorized)
fmt.Fprintln(w, `{"error":{"message":"bar","type":"`+ErrorTypeInvalidRequest+`"}}`)
}))
defer ts.Close()
backend := GetBackendWithConfig(APIBackend, &BackendConfig{
URL: ts.URL,
})
err := backend.Call(http.MethodGet, "/v1/account", "sk_test_badKey", nil, nil)
assert.Error(t, err)
stripeErr := err.(*Error)
assert.Equal(t, ErrorTypeInvalidRequest, stripeErr.Type)
assert.Equal(t, "req_123", stripeErr.RequestID)
assert.Equal(t, 401, stripeErr.HTTPStatusCode)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。