@@ -106,6 +106,11 @@ func (c *CfClient) RestAPI(ctx context.Context, opt *RequestOptions) ([]byte, er
106106 return nil , err
107107 }
108108
109+ res , err = c .wrapResponse (res )
110+ if err != nil {
111+ return nil , err
112+ }
113+
109114 defer res .Body .Close ()
110115 bytes , err := io .ReadAll (res .Body )
111116 if err != nil {
@@ -114,6 +119,9 @@ func (c *CfClient) RestAPI(ctx context.Context, opt *RequestOptions) ([]byte, er
114119
115120 return bytes , nil
116121}
122+ func (c * CfClient ) NativeRestAPI (ctx context.Context , opt * RequestOptions ) (* http.Response , error ) {
123+ return c .apiCall (ctx , c .baseUrl , opt )
124+ }
117125
118126func (c * CfClient ) GraphqlAPI (ctx context.Context , query string , variables any , result any ) error {
119127 body := map [string ]any {
@@ -128,6 +136,11 @@ func (c *CfClient) GraphqlAPI(ctx context.Context, query string, variables any,
128136 return err
129137 }
130138
139+ res , err = c .wrapResponse (res )
140+ if err != nil {
141+ return err
142+ }
143+
131144 defer res .Body .Close ()
132145 bytes , err := io .ReadAll (res .Body )
133146 if err != nil {
@@ -175,6 +188,10 @@ func (c *CfClient) apiCall(ctx context.Context, baseUrl *url.URL, opt *RequestOp
175188 return nil , fmt .Errorf ("failed to send request: %w" , err )
176189 }
177190
191+ return res , nil
192+ }
193+
194+ func (c * CfClient ) wrapResponse (res * http.Response ) (* http.Response , error ) {
178195 if res .StatusCode >= http .StatusBadRequest {
179196 defer res .Body .Close ()
180197 bytes , err := io .ReadAll (res .Body )
@@ -189,7 +206,6 @@ func (c *CfClient) apiCall(ctx context.Context, baseUrl *url.URL, opt *RequestOp
189206 body : body ,
190207 }
191208 }
192-
193209 return res , nil
194210}
195211
0 commit comments