Skip to content

Fix/graphql handler errors#156

Merged
Yehonal merged 7 commits intomasterfrom
fix/graphql_handler_errors
Jul 16, 2025
Merged

Fix/graphql handler errors#156
Yehonal merged 7 commits intomasterfrom
fix/graphql_handler_errors

Conversation

@vpintidev
Copy link
Collaborator

Description of the Change

This PR introduces a static method AcoreUtils::handle_acore_error() that provides unified error handling for both GraphQL and standard WordPress requests.

Purpose

The goal is to centralize error handling logic across the plugin and ensure consistent behavior depending on the request context:

  • GraphQL requests: If GRAPHQL_HTTP_REQUEST is defined and set to true, a UserError exception is thrown, which is properly handled by the GraphQL layer.
  • Standard WordPress requests: The user is redirected to the plugin's settings page, and an admin notice is displayed with the provided error message.

Benefits

  • Avoids duplicated error-handling logic throughout the codebase.
  • Ensures GraphQL clients receive well-structured error responses.
  • Provides a better UX for admin users when issues occur in the standard WP context.

Technical Notes

  • The GRAPHQL_HTTP_REQUEST constant is defined by WPGraphQL to indicate incoming GraphQL HTTP requests.
  • wp_redirect() is followed by exit to stop further execution after redirecting.
  • esc_html() is used to ensure safe output in the admin notice.

Potential Improvements

  • Consider integrating logging for error tracking and diagnostics.
  • Optionally extend support to handle REST API requests with JSON error responses in the future.

@vpintidev vpintidev requested a review from Yehonal June 25, 2025 20:29
@vpintidev vpintidev requested a review from Yehonal June 26, 2025 19:25
vpinti and others added 4 commits June 27, 2025 19:32
- Added a reusable flash message system for admin notices.
- Registered the flash message display with the admin_notices hook.
- Improved the wp_login hook to work reliably with $_POST data.
- Added a dedicated hook for GraphQL login (graphql_login_after_authenticate) to support account creation
@Yehonal Yehonal merged commit baa570a into master Jul 16, 2025
1 check passed
@Yehonal Yehonal deleted the fix/graphql_handler_errors branch July 16, 2025 06:29
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