Skip to content
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

Add HttpErrorCodeInterface. #18110

Merged
merged 1 commit into from
Dec 30, 2024
Merged

Add HttpErrorCodeInterface. #18110

merged 1 commit into from
Dec 30, 2024

Conversation

ADmad
Copy link
Member

@ADmad ADmad commented Dec 28, 2024

Using this interface allows exception classes to indicate that they use HTTP error codes and avoid having to maintain an error class to HTTP error code map in WebExceptionRenderer.

@ADmad ADmad added this to the 5.2.0 milestone Dec 28, 2024
@ADmad ADmad force-pushed the feat/5.2-http-exception-interface branch 2 times, most recently from e740154 to de5e52a Compare December 28, 2024 02:46

use Throwable;

interface HttpErrorCodeInterface extends Throwable
Copy link
Member Author

Choose a reason for hiding this comment

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

Ideally this should have been in the Http package but couple of exceptions of the Datasource package are also mapped to 404 code :/

Copy link
Member

@othercorey othercorey Dec 28, 2024

Choose a reason for hiding this comment

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

I think this is ok. Hard to create a generic map with one way dependencies with our split packages.

Copy link
Member

Choose a reason for hiding this comment

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

Do we get much from extending Throwable?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not really, I did it as this interface is only meant to be used by exception classes.

@ADmad
Copy link
Member Author

ADmad commented Dec 28, 2024

The static analysis job failure is because the composer.json of split packages use cakephp 5.1.

@dereuromark
Copy link
Member

We should be using dev branches I guess

@ADmad ADmad force-pushed the feat/5.2-http-exception-interface branch from de5e52a to 3e97a14 Compare December 28, 2024 10:51
@ADmad
Copy link
Member Author

ADmad commented Dec 28, 2024

We should be using dev branches I guess

Even that doesn't help, since the new interface file is in this PR. The error will be gone only after the PR is merged.

* @var array<string, int>
* @psalm-var array<class-string<\Throwable>, int>
*/
protected array $exceptionHttpCodes = [
Copy link
Member

Choose a reason for hiding this comment

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

We could end up breaking userland exception rendering with this change. If we wanted to avoid the breakage, we could retain this as an empty list and also retain line 408 as a fallback for exceptions that don't implement HttpErrorCodeInterface

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, I'll add it back for BC.


use Throwable;

interface HttpErrorCodeInterface extends Throwable
Copy link
Member

Choose a reason for hiding this comment

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

Do we get much from extending Throwable?

@ADmad ADmad force-pushed the feat/5.2-http-exception-interface branch from 3e97a14 to 1e2087f Compare December 29, 2024 13:12
Using this interface allows exception classes to indicate that they
use HTTP error codes and avoid having to maintain an error class to HTTP error code
map in WebExceptionRenderer.
@ADmad ADmad force-pushed the feat/5.2-http-exception-interface branch from 1e2087f to d5d72da Compare December 29, 2024 13:12
@markstory
Copy link
Member

Looks good to me. The split package phpstan builds are failling. Those builds might clear up after we do a release though.

@ADmad ADmad merged commit 219a8f2 into 5.next Dec 30, 2024
12 of 13 checks passed
@ADmad ADmad deleted the feat/5.2-http-exception-interface branch December 30, 2024 02:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants