20 lines
617 B
Go
20 lines
617 B
Go
package threadsapi
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseAPIErrorIncludesUserMessageAndCodes(t *testing.T) {
|
|
body := []byte(`{"error":{"message":"An unknown error occurred","type":"OAuthException","code":1,"error_subcode":99,"error_user_msg":"圖片無法下載","fbtrace_id":"abc123"}}`)
|
|
err := parseAPIError(body, 400)
|
|
got := err.Error()
|
|
if got == "" {
|
|
t.Fatal("expected error")
|
|
}
|
|
for _, want := range []string{"400", "圖片無法下載", "code=1", "subcode=99", "fbtrace_id=abc123"} {
|
|
if !strings.Contains(got, want) {
|
|
t.Fatalf("parseAPIError() = %q, want fragment %q", got, want)
|
|
}
|
|
}
|
|
} |