MCPcopy Index your code
hub / github.com/cloudquery/cloudquery / ErrorFromHTTPResponse

Function ErrorFromHTTPResponse

cli/internal/hub/util.go:51–68  ·  view source on GitHub ↗
(httpResp *http.Response, resp any)

Source from the content-addressed store, hash-verified

49}
50
51func ErrorFromHTTPResponse(httpResp *http.Response, resp any) error {
52 fields := make(map[string]any)
53 el := reflect.ValueOf(resp).Elem()
54 for i := 0; i < el.NumField(); i++ {
55 f := el.Field(i)
56 fields[el.Type().Field(i).Name] = f.Interface()
57 }
58 for k, v := range fields {
59 if !strings.HasPrefix(k, "JSON") || v == nil || reflect.ValueOf(v).Elem().Kind() != reflect.Struct {
60 continue
61 }
62 msg := reflect.ValueOf(v).Elem().FieldByName("Message")
63 if msg.IsValid() {
64 return fmt.Errorf("%s: %s", strings.TrimPrefix(k, "JSON"), msg.String())
65 }
66 }
67 return fmt.Errorf("error code: %v", httpResp.StatusCode)
68}
69
70func UploadFile(uploadURL, localPath string) error {
71 return UploadFileWithContentType(context.Background(), uploadURL, localPath, "application/octet-stream")

Callers

nothing calls this directly

Calls 3

ErrorfMethod · 0.80
TypeMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected