Skip to content

Return a 503 for specific PDO exceptions, alternate mix#4720

Closed
paul-m wants to merge 1 commit into
4.xfrom
503-for-max-connections-subscriber
Closed

Return a 503 for specific PDO exceptions, alternate mix#4720
paul-m wants to merge 1 commit into
4.xfrom
503-for-max-connections-subscriber

Conversation

@paul-m

@paul-m paul-m commented May 14, 2026

Copy link
Copy Markdown
Contributor

Fixes [issue#]

Describe your changes

This is another way to do #4704 much more generalized.

  • Marks DKAN API routes as DKAN API routes in the yml files.
  • Adds an exception event subscriber, so we can handle specific exceptions.
  • We're handling the case of a \PDOException with a code of 1203 (too many connections).
  • Always return a JsonResponse with a 503 response code for this exception, and a Retry-After header of our choosing.

To see it in action, make a local and modify an API controller method to throw the exception. I suggest Drupal\dkan_datastore\Controller\AbstractQueryController::queryResource. Throw an exception like this:

    throw new \PDOException(
      'AI bots taking over.', 1203
    );

Now request: https://dkan.ddev.site/api/1/datastore/query/8701d18a-5792-5451-8700-a621bccc5f6e

See a message like this:

{
"message": "Try again later after 120 seconds.",
"code": 503
}

Watchdog should show you a message like: "PDOException (code: 1203) AI bots taking over."

QA Steps

  • Add manual QA steps in checklist format for a reviewer to perform. Be as specific as possible, provide examples if appropriate.

Checklist before requesting review

If any of these are left unchecked, please provide an explanation

  • I have updated or added tests to cover my code
  • I have updated or added documentation

@paul-m paul-m changed the title Return a 503 for specific PDO exceptions Return a 503 for specific PDO exceptions, alternate mix May 14, 2026
@paul-m

paul-m commented May 29, 2026

Copy link
Copy Markdown
Contributor Author

Closed in favor of handling this in the controller: #4704

@paul-m paul-m closed this May 29, 2026
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