decodeJSON reads a JSON response body into v and closes it. A body cut short is reported as a *url.Error, like a request that failed in transit, so callers can tell it apart from a response of an unexpected shape.
(resp *http.Response, v any)
| 186 | // decodeJSON reads a JSON response body into v and closes it. A body cut short is reported as a *url.Error, like a |
| 187 | // request that failed in transit, so callers can tell it apart from a response of an unexpected shape. |
| 188 | func decodeJSON(resp *http.Response, v any) error { |
| 189 | defer resp.Body.Close() |
| 190 | body, err := io.ReadAll(resp.Body) |
| 191 | if err != nil { |
| 192 | return &url.Error{Op: resp.Request.Method, URL: resp.Request.URL.String(), Err: err} |
| 193 | } |
| 194 | |
| 195 | if err := json.Unmarshal(body, v); err != nil { |
| 196 | return fmt.Errorf("failed to decode response: %w", err) |
| 197 | } |
| 198 | return nil |
| 199 | } |
| 200 | |
| 201 | func (c *eventClient) DeleteSubscription(ctx context.Context, id string) error { |
| 202 | if !SupportedHost(c.host) { |
no test coverage detected