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

4336: Return 400 error on invalid JSON sent to the datastore API #4341

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from

Conversation

janette
Copy link
Member

@janette janette commented Nov 15, 2024

Fixes #4336

Describe your changes

Better response for invalid JSON

QA Steps

  • Run the following POST
POST https://demo.getdkan.org/api/1/datastore/query/cedcd327-4e5d-43f9-8eb1-c11850fa7c55/0 HTTP/1.1

{
  "conditions": [
}
  • Confirm you get a 400 error and "Invalid JSON" message

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

@janette janette marked this pull request as ready for review November 15, 2024 19:07
@@ -221,6 +221,9 @@ protected function extractMetastoreDependencies(DatastoreQuery $datastoreQuery):
protected function buildDatastoreQuery(Request $request, mixed $identifier = NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

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

\Drupal\datastore\Controller\QueryDownloadController::buildDatastoreQuery() overrides this... Both call getPayloadJson() which is probably where we should throw the exception.

So: Move this checking to either getPayloadJson() or fixTypes(), and add a bad JSON test for both query controller and download query controller.

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.

Invalid JSON causes datastore API to throw 500
2 participants