Skip to content

Conversation

junaidbinfarooq
Copy link
Contributor

Q A
Bug fix? yes
New feature? no
Docs? no
Issues Fix #528 Builds on #538
License MIT

@carsonbot carsonbot added Bug Something isn't working Platform Issues & PRs about the AI Platform component Status: Needs Review labels Sep 15, 2025
@carsonbot carsonbot changed the title [platform] Add status code 429 to rate limit exceeded exception [Platform] Add status code 429 to rate limit exceeded exception Sep 15, 2025
@OskarStark
Copy link
Contributor

Is it really common to use the status code as exception code?

@junaidbinfarooq
Copy link
Contributor Author

Is it really common to use the status code as exception code?

Generally speaking, it does make sense to have the code present, and application-level code can be interested in the exception code, which in this case would map to the 429 status code.

@VincentLanglet
Copy link
Contributor

Is it really common to use the status code as exception code?

Definitely no.
Even the HttpException from symfony are using a different value for the status code and the code
https://github.com/symfony/symfony/blob/7.4/src/Symfony/Component/HttpKernel/Exception/HttpException.php

This PR start to creating a confusion between both IMHO.

application-level code can be interested in the exception code, which in this case would map to the 429 status code.

You can manually do the mapping

match ($exception::class) {
     RateLimitExceededException::class => 429,
     // ...
}

@junaidbinfarooq
Copy link
Contributor Author

Is it really common to use the status code as exception code?

Definitely no. Even the HttpException from symfony are using a different value for the status code and the code https://github.com/symfony/symfony/blob/7.4/src/Symfony/Component/HttpKernel/Exception/HttpException.php

This PR start to creating a confusion between both IMHO.

application-level code can be interested in the exception code, which in this case would map to the 429 status code.

You can manually do the mapping

match ($exception::class) {
     RateLimitExceededException::class => 429,
     // ...
}

There are libraries where the two are kept separate, and likely some where the code is directly mapped to the status code, especially in the context of HTTP, but PHP doesn't care how you decide to use the exception code property, AFAIK.

You can manually do the mapping

Why? You shared the example of Symfony's HttpException class. Does it not have a status code field so that the application users get the status code OOTB?

Perhaps, we can have a status code field here too.
WDYT @chr-hertel @OskarStark ?

@OskarStark
Copy link
Contributor

a statusCode field makes much more sense to me

@VincentLanglet
Copy link
Contributor

a statusCode field makes much more sense to me

Since we have mutiple exception, like #543
This would certainly mean introducing some HttpException base exception with a status code field.

I dunno @chr-hertel @OskarStark if we should

  • Try to reuse the HttpException from Symfony
  • Or recreating them in the symfony/ai context like we're starting to do

@junaidbinfarooq
Copy link
Contributor Author

a statusCode field makes much more sense to me

@chr-hertel @OskarStark
Should we, in this case, create something like an HttpException base class with the status code field that extends from the platform's RuntimeException?

@junaidbinfarooq
Copy link
Contributor Author

@chr-hertel @OskarStark
Could you have a look?

@OskarStark
Copy link
Contributor

a statusCode would work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Platform Issues & PRs about the AI Platform component Status: Needs Review Status: Needs Work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Platform] Expose API errors for better Developer Experience
4 participants