Uploaded image for project: 'Solr'
  1. Solr
  2. SOLR-8836

/update should return BAD REQUEST when invalid JSON provided

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Trivial
    • Resolution: Fixed
    • Affects Version/s: 6.0
    • Fix Version/s: 6.0
    • Component/s: None
    • Labels:
      None

      Description

      When a user provides invalid JSON to the /update endpoint, the request fails with a 500 (INTERNAL SERVER ERROR). If the user looks at the response body, they'll see a message indicating that the provided JSON was invalid. However, going from the status code alone, the failure is indistinguishable from a true server-error. This is a bit misleading. It would be nice if Solr instead returned a 400 (BAD REQUEST) status code when it detects invalid arguments.

      Reproduction Steps:
      1.) bin/solr start -e cloud -noprompt
      2.) curl -i -l -k -X POST -H 'Content-Type: application/json' 'http://localhost:8983/solr/gettingstarted/update' --data-binary '}{'

      1. SOLR-8836.patch
        3 kB
        Jason Gerlowski
      2. SOLR-8836.patch
        1 kB
        Jason Gerlowski

        Activity

        Hide
        gerlowskija Jason Gerlowski added a comment -

        A simple patch demonstrating a fix for the issue. With this fix, /update answers invalid JSON with the response:

        [~/c/s/l/solr] $ curl -i -l -k -X POST -H 'Content-Type: application/json' 'http://localhost:7574/solr/gettingstarted/update' --data-binary '}{'
        HTTP/1.1 400 Bad Request
        
        {"responseHeader":{"status":400,"QTime":11},"error":{"metadata":["error-class","org.apache.solr.common.SolrException","root-error-class","org.noggit.JSONParser$ParseException"],"msg":"org.noggit.JSONParser$ParseException: JSON Parse Error: char=},position=0 BEFORE='}' AFTER='{'","code":400}}
        

        This fixes the status code, but the response body is a little odd. I'm not quite sure where the "metadata", "error-class", "root-error-class" nesting comes from. Still some details of Solr's error reporting that I'm brushing up on; bit of a work-in-progress.

        Show
        gerlowskija Jason Gerlowski added a comment - A simple patch demonstrating a fix for the issue. With this fix, /update answers invalid JSON with the response: [~/c/s/l/solr] $ curl -i -l -k -X POST -H 'Content-Type: application/json' 'http: //localhost:7574/solr/gettingstarted/update' --data-binary '}{' HTTP/1.1 400 Bad Request { "responseHeader" :{ "status" :400, "QTime" :11}, "error" :{ "metadata" :[ "error-class" , "org.apache.solr.common.SolrException" , "root-error-class" , "org.noggit.JSONParser$ParseException" ], "msg" : "org.noggit.JSONParser$ParseException: JSON Parse Error: char =},position=0 BEFORE='}' AFTER='{'" , "code" :400}} This fixes the status code, but the response body is a little odd. I'm not quite sure where the "metadata", "error-class", "root-error-class" nesting comes from. Still some details of Solr's error reporting that I'm brushing up on; bit of a work-in-progress.
        Hide
        gerlowskija Jason Gerlowski added a comment -

        Looking into Solr's error messages more, I think the error-message is pretty standard when SolrException is used. So I'm fine with it now.

        Latest patch adds a test, which ensures 400 is returned. All tests pass locally.

        Patch should be ready for review if anyone has interest in seeing this change get in.

        Show
        gerlowskija Jason Gerlowski added a comment - Looking into Solr's error messages more, I think the error-message is pretty standard when SolrException is used. So I'm fine with it now. Latest patch adds a test, which ensures 400 is returned. All tests pass locally. Patch should be ready for review if anyone has interest in seeing this change get in.
        Hide
        anshumg Anshum Gupta added a comment -

        Thanks Jason.
        LGTM, I'll run the tests and commit.

        Show
        anshumg Anshum Gupta added a comment - Thanks Jason. LGTM, I'll run the tests and commit.
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 30a77b73b603ba52a50da397aefc6f9a88f05732 in lucene-solr's branch refs/heads/master from anshum
        [ https://git-wip-us.apache.org/repos/asf?p=lucene-solr.git;h=30a77b7 ]

        SOLR-8836: Return 400, and a SolrException when an invalid json is provided to the update handler instead of 500.

        Show
        jira-bot ASF subversion and git services added a comment - Commit 30a77b73b603ba52a50da397aefc6f9a88f05732 in lucene-solr's branch refs/heads/master from anshum [ https://git-wip-us.apache.org/repos/asf?p=lucene-solr.git;h=30a77b7 ] SOLR-8836 : Return 400, and a SolrException when an invalid json is provided to the update handler instead of 500.
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit 4deb4cd1bac4d18914164fccc3e377eb8f11a117 in lucene-solr's branch refs/heads/branch_6x from anshum
        [ https://git-wip-us.apache.org/repos/asf?p=lucene-solr.git;h=4deb4cd ]

        SOLR-8836: Return 400, and a SolrException when an invalid json is provided to the update handler instead of 500.

        Show
        jira-bot ASF subversion and git services added a comment - Commit 4deb4cd1bac4d18914164fccc3e377eb8f11a117 in lucene-solr's branch refs/heads/branch_6x from anshum [ https://git-wip-us.apache.org/repos/asf?p=lucene-solr.git;h=4deb4cd ] SOLR-8836 : Return 400, and a SolrException when an invalid json is provided to the update handler instead of 500.
        Hide
        jira-bot ASF subversion and git services added a comment -

        Commit cd070d7b17955fc3cc10f013e9694946c5ce1c88 in lucene-solr's branch refs/heads/branch_6_0 from anshum
        [ https://git-wip-us.apache.org/repos/asf?p=lucene-solr.git;h=cd070d7 ]

        SOLR-8836: Return 400, and a SolrException when an invalid json is provided to the update handler instead of 500.

        Show
        jira-bot ASF subversion and git services added a comment - Commit cd070d7b17955fc3cc10f013e9694946c5ce1c88 in lucene-solr's branch refs/heads/branch_6_0 from anshum [ https://git-wip-us.apache.org/repos/asf?p=lucene-solr.git;h=cd070d7 ] SOLR-8836 : Return 400, and a SolrException when an invalid json is provided to the update handler instead of 500.
        Hide
        anshumg Anshum Gupta added a comment -

        Thanks Jason.

        Show
        anshumg Anshum Gupta added a comment - Thanks Jason.

          People

          • Assignee:
            anshumg Anshum Gupta
            Reporter:
            gerlowskija Jason Gerlowski
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development