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)
| 175 | // decodeJSON reads a JSON response body into v and closes it. A body cut short is reported as a *url.Error, like a |
| 176 | // request that failed in transit, so callers can tell it apart from a response of an unexpected shape. |
| 177 | func decodeJSON(resp *http.Response, v any) error { |
| 178 | defer resp.Body.Close() |
| 179 | body, err := io.ReadAll(resp.Body) |
| 180 | if err != nil { |
| 181 | return &url.Error{Op: resp.Request.Method, URL: resp.Request.URL.String(), Err: err} |
| 182 | } |
| 183 | |
| 184 | if err := json.Unmarshal(body, v); err != nil { |
| 185 | return fmt.Errorf("failed to decode response: %w", err) |
| 186 | } |
| 187 | return nil |
| 188 | } |
| 189 | |
| 190 | func (c *eventClient) DeleteSubscription(ctx context.Context, id string) error { |
| 191 | if !SupportedHost(c.host) { |
no test coverage detected