Skip to content

Conversation

@itashia
Copy link
Contributor

@itashia itashia commented May 24, 2025

No description provided.

@amirdaraby
Copy link
Owner

please create an specific service provider for this and explain what it does, thank you

@itashia
Copy link
Contributor Author

itashia commented May 24, 2025

please create an specific service provider for this and explain what it does, thank you

The code registers a custom handler for validation exceptions that:

Checks if the request expects JSON response (API calls)

If yes, returns a JSON response containing:

success: false flag

A translated validation error message

The actual validation errors from the exception

HTTP status code 422 (Unprocessable Entity)

The response is sent with 422 HTTP status code

Previously, validation errors were returned as HTML views (typical for web forms), but now when the request comes from an API (expects JSON), the errors are returned in JSON format instead. This is particularly useful for API development where you want consistent JSON error responses rather than HTML views.

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.

2 participants