Skip to content

feat(ai-proxy): add UnauthorizedError/TooManyRequestsError and typed AI provider errors#1474

Open
Scra3 wants to merge 9 commits intomainfrom
feat/add-unauthorized-toomany-errors
Open

feat(ai-proxy): add UnauthorizedError/TooManyRequestsError and typed AI provider errors#1474
Scra3 wants to merge 9 commits intomainfrom
feat/add-unauthorized-toomany-errors

Conversation

@Scra3
Copy link
Member

@Scra3 Scra3 commented Feb 17, 2026

Summary

  • Add UnauthorizedError (401) and TooManyRequestsError (429) to agent-toolkit, re-exported from datasource-toolkit
  • Add httpCode property to BusinessError and all subclasses
  • Add corresponding cases in the agent's error-handling middleware
  • Create typed AI provider errors in ai-proxy:
    • AIProviderError — generic provider error (builds message from cause)
    • AITooManyRequestsError — wraps 429 from providers
    • AIUnauthorizedError — wraps 401 from providers
  • Refactor wrapProviderError to use typed errors instead of generic AIUnprocessableError
  • Add hierarchy tests for new error classes

@qltysh
Copy link

qltysh bot commented Feb 17, 2026

3 new issues

Tool Category Rule Count
qlty Structure Function with many returns (count = 8): getErrorStatus 2
qlty Structure Function with many parameters (count = 4): constructor 1

@qltysh
Copy link

qltysh bot commented Feb 17, 2026

Qlty

Coverage Impact

⬆️ Merging this pull request will increase total coverage on main by 0.01%.

Modified Files with Diff Coverage (6)

RatingFile% DiffUncovered Line #s
Coverage rating: A Coverage rating: A
packages/ai-proxy/src/provider-dispatcher.ts100.0%
Coverage rating: A Coverage rating: A
packages/ai-proxy/src/errors.ts100.0%
Coverage rating: A Coverage rating: A
packages/datasource-toolkit/src/errors.ts100.0%
Coverage rating: A Coverage rating: A
packages/agent/src/routes/system/error-handling.ts100.0%
Coverage rating: A Coverage rating: A
packages/agent-toolkit/src/errors.ts100.0%
Coverage rating: A Coverage rating: A
packages/agent/src/types.ts100.0%
Total100.0%
🚦 See full report on Qlty Cloud »

🛟 Help
  • Diff Coverage: Coverage for added or modified lines of code (excludes deleted files). Learn more.

  • Total Coverage: Coverage for the whole repository, calculated as the sum of all File Coverage. Learn more.

  • File Coverage: Covered Lines divided by Covered Lines plus Missed Lines. (Excludes non-executable lines including blank lines and comments.)

    • Indirect Changes: Changes to File Coverage for files that were not modified in this PR. Learn more.

Base automatically changed from refactor/move-http-errors-to-agent-toolkit to main February 18, 2026 10:26
alban bertolini and others added 6 commits February 18, 2026 11:37
…AI provider errors

- Add UnauthorizedError (401) and TooManyRequestsError (429) to agent-toolkit
- Re-export from datasource-toolkit for backward compatibility
- Add HTTP codes and cases in agent error-handling middleware
- Create AIProviderError, AIRateLimitError, AIAuthenticationError in ai-proxy
  with baseBusinessErrorName overrides for correct HTTP status mapping
- Update wrapProviderError to use typed errors instead of generic AIUnprocessableError

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add `status` property to BusinessError and all subclasses, simplifying
the error-handling middleware from a 30-line switch/case to a direct
status lookup.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…r class

The provider name and cause detail are now assembled by the constructor,
simplifying wrapProviderError callers.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…tibility

The simplified error.status lookup would break if the user upgrades
agent without upgrading datasource-toolkit (old errors lack the status
property).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…rror, AIAuthenticationError

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Scra3 Scra3 force-pushed the feat/add-unauthorized-toomany-errors branch 2 times, most recently from d397d17 to 7057a1c Compare February 18, 2026 10:46
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Scra3 Scra3 force-pushed the feat/add-unauthorized-toomany-errors branch from 7057a1c to d189c01 Compare February 18, 2026 10:56
alban bertolini and others added 2 commits February 18, 2026 12:18
…r classes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ify constructor

- AIRateLimitError -> AITooManyRequestsError (matches TooManyRequestsError)
- AIAuthenticationError -> AIUnauthorizedError (matches UnauthorizedError)
- Remove message from AIProviderError options, build it from cause
- Type cause as Error instead of unknown

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant

Comments