8000 feat: populate rate limited properties on RatelimitedLinearError by urossmolnik · Pull Request #694 · linear/linear · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: populate rate limited properties on RatelimitedLinearError #694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

urossmolnik
Copy link
Contributor

No description provided.

Copy link
linear bot commented Apr 30, 2025

@charliecreates charliecreates bot requested a review from CharlieHelps April 30, 2025 18:32
Copy link
changeset-bot bot commented Apr 30, 2025

🦋 Changeset detected

Latest commit: f59c38d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@linear/sdk Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
@charliecreates charliecreates bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current implementation using Number(... ) ?? undefined will yield 0 or NaN for missing or invalid headers rather than undefined. It’s recommended to explicitly check the header’s presence and guard against NaN. Consider extracting a helper for header parsing to reduce repetition.

Summary of changes

Added Rate Limit Properties to RatelimitedLinearError

  • Introduced seven new properties on RatelimitedLinearError:

    • retryAfter
    • requestsLimit
    • requestsRemaining
    • requestsResetAt
    • complexityLimit
    • complexityRemaining
    • complexityResetAt
  • Each property is populated from response headers using Number(error?.response?.headers?.get(...)) ?? undefined.

Changelog

  • Created a new changeset for version bump: .changeset/fuzzy-mangos-yawn.md

Comment on lines 123 to 129
this.retryAfter = Number(error?.response?.headers?.get("retry-after")) ?? undefined;
this.requestsLimit = Number(error?.response?.headers?.get("x-ratelimit-requests-limit")) ?? undefined;
this.requestsRemaining = Number(error?.response?.headers?.get("x-ratelimit-requests-remaining")) ?? undefined;
this.requestsResetAt = Number(error?.response?.headers?.get("x-ratelimit-requests-reset")) ?? undefined;
this.complexityLimit = Number(error?.response?.headers?.get("x-ratelimit-complexity-limit") 8000 ) ?? undefined;
this.complexityRemaining = Number(error?.response?.headers?.get("x-ratelimit-complexity-remaining")) ?? undefined;
this.complexityResetAt = Number(error?.response?.headers?.get("x-ratelimit-complexity-reset")) ?? undefined;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using Number(... ) ?? undefined does not guard against missing or invalid headers correctly:

  • If headers.get(...) returns null, Number(null) yields 0, so you’ll get 0 instead of undefined when the header is absent.
  • If it returns undefined, Number(undefined) yields NaN, which is not replaced by undefined due to NaN ?? undefined evaluating to NaN.

You should explicitly check whether the header value is null or undefined before converting it, and also guard against NaN results.

Suggestion

Refactor header parsing to handle missing headers and invalid numbers correctly. For example:

const headers = error?.response?.headers;
const parseHeader = (key: string): number | undefined => {
  const value = headers?.get(key);
  if (value == null) return undefined;
  const num = Number(value);
  return Number.isNaN(num) ? undefined : num;
};

this.retryAfter = parseHeader('retry-after');
this.requestsLimit = parseHeader('x-ratelimit-requests-limit');
this.requestsRemaining = parseHeader('x-ratelimit-requests-remaining');
this.requestsResetAt = parseHeader('x-ratelimit-requests-reset');
this.complexityLimit = parseHeader('x-ratelimit-complexity-limit');
this.complexityRemaining = parseHeader('x-ratelimit-complexity-remaining');
this.complexityResetAt = parseHeader('x-ratelimit-complexity-reset');

Reply with "@CharlieHelps yes please" if you'd like me to add a commit with this suggestion

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks like a good suggestion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@charliecreates charliecreates bot removed the request for review from CharlieHelps April 30, 2025 18:34
@urossmolnik urossmolnik force-pushed the uros/lin-34865-expose-rate-limit-info-in-the-typescript-sdk branch from 8e945b5 to 0b3c924 Compare April 30, 2025 18:55
@urossmolnik urossmolnik force-pushed the uros/lin-34865-expose-rate-limit-info-in-the-typescript-sdk branch from 0b3c924 to f59c38d Compare April 30, 2025 18:55
@urossmolnik urossmolnik merged commit d1175c1 into master Apr 30, 2025
2 checks passed
@urossmolnik urossmolnik deleted the uros/lin-34865-expose-rate-limit-info-in-the-typescript-sdk branch April 30, 2025 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0