(ctx context.Context, id string)
| 212 | } |
| 213 | |
| 214 | func (c *eventClient) OpenStream(ctx context.Context, id string) (io.ReadCloser, error) { |
| 215 | if !SupportedHost(c.host) { |
| 216 | return nil, ErrUnsupportedHost |
| 217 | } |
| 218 | |
| 219 | path, err := safeurl.JoinPath("event-subscriptions", id, "events") |
| 220 | if err != nil { |
| 221 | return nil, err |
| 222 | } |
| 223 | |
| 224 | resp, err := c.api.RequestWithContext(ctx, c.host, http.MethodGet, path.String(), nil, api.WithHeader("Accept", "text/event-stream")) |
| 225 | if err != nil { |
| 226 | if httpErr, ok := errors.AsType[api.HTTPError](err); ok { |
| 227 | switch { |
| 228 | case httpErr.StatusCode == http.StatusNotFound: |
| 229 | return nil, fmt.Errorf("%w: %w", ErrSubscriptionNotFound, err) |
| 230 | case httpErr.StatusCode == http.StatusForbidden: |
| 231 | return nil, forbiddenError(httpErr, err) |
| 232 | } |
| 233 | } |
| 234 | return nil, err |
| 235 | } |
| 236 | mediaType, _, _ := mime.ParseMediaType(resp.Header.Get("Content-Type")) |
| 237 | if mediaType != "text/event-stream" { |
| 238 | resp.Body.Close() |
| 239 | return nil, fmt.Errorf("unexpected event stream content type %q", resp.Header.Get("Content-Type")) |
| 240 | } |
| 241 | return resp.Body, nil |
| 242 | } |
| 243 | |
| 244 | // forbiddenError tells a 403 response for an account without preview access apart from other denials. It keeps the |
| 245 | // HTTP error wrapped, so callers treat it as final rather than retrying it. |
nothing calls this directly
no test coverage detected