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

Wrong status code in case of invalid requests

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Duplicate
    • 6.5
    • None
    • None
    • None

    Description

      I have small document set take from here - http://yonik.com/solr-nested-objects/
      According to the schema, review_dt is of type date and pubyear_i is of type int

      This request,
      http://localhost:8983/solr/blockjoin70001-1492010056/select?q=*:*&fq=review_dt:[something%20TO%20anything]&wt=json returns
      returns 400 as expected since, wrong range query is fired

      {
        "responseHeader": {
          "status": 400,
          "QTime": 2,
          "params": {
            "q": "*:*",
            "fq": "review_dt:[something TO anything]",
            "wt": "json"
          }
        },
        "error": {
          "metadata": [
            "error-class",
            "org.apache.solr.common.SolrException",
            "root-error-class",
            "org.apache.solr.common.SolrException"
          ],
          "msg": "Invalid Date String:'something'",
          "code": 400
        }
      }
      

      but for this request,
      http://localhost:8983/solr/blockjoin70001-1492010056/select?q=*:*&fq=pubyear_i:[something%20TO%20anything]&wt=json returns 500(Internal server error) instead of 400(Bad Request)

      {
        "responseHeader": {
          "status": 500,
          "QTime": 11,
          "params": {
            "q": "*:*",
            "fq": "pubyear_i:[something TO anything]",
            "wt": "json"
          }
        },
        "error": {
          "msg": "For input string: \"something\"",
          "trace": "java.lang.NumberFormatException: For input string: \"something\"\n\tat java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)\n\tat java.lang.Integer.parseInt(Integer.java:580)\n\tat java.lang.Integer.parseInt(Integer.java:615)\n\tat org.apache.solr.schema.TrieField.getRangeQuery(TrieField.java:373)\n\tat org.apache.solr.parser.SolrQueryParserBase.getRangeQueryImpl(SolrQueryParserBase.java:1047)\n\tat org.apache.solr.parser.SolrQueryParserBase.getRangeQuery(SolrQueryParserBase.java:1041)\n\tat org.apache.solr.parser.QueryParser.Term(QueryParser.java:503)\n\tat org.apache.solr.parser.QueryParser.Clause(QueryParser.java:277)\n\tat org.apache.solr.parser.QueryParser.Query(QueryParser.java:161)\n\tat org.apache.solr.parser.QueryParser.TopLevelQuery(QueryParser.java:130)\n\tat org.apache.solr.parser.SolrQueryParserBase.parse(SolrQueryParserBase.java:211)\n\tat org.apache.solr.search.LuceneQParser.parse(LuceneQParser.java:53)\n\tat org.apache.solr.search.QParser.getQuery(QParser.java:168)\n\tat org.apache.solr.handler.component.QueryComponent.prepare(QueryComponent.java:212)\n\tat org.apache.solr.handler.component.SearchHandler.handleRequestBody(SearchHandler.java:269)\n\tat org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:173)\n\tat org.apache.solr.core.SolrCore.execute(SolrCore.java:2440)\n\tat org.apache.solr.servlet.HttpSolrCall.execute(HttpSolrCall.java:723)\n\tat org.apache.solr.servlet.HttpSolrCall.call(HttpSolrCall.java:529)\n\tat org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:347)\n\tat org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:298)\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1691)\n\tat org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:582)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)\n\tat org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)\n\tat org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)\n\tat org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1180)\n\tat org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:512)\n\tat org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)\n\tat org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1112)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)\n\tat org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:213)\n\tat org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:119)\n\tat org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)\n\tat org.eclipse.jetty.rewrite.handler.RewriteHandler.handle(RewriteHandler.java:335)\n\tat org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)\n\tat org.eclipse.jetty.server.Server.handle(Server.java:534)\n\tat org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:320)\n\tat org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251)\n\tat org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:273)\n\tat org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)\n\tat org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:93)\n\tat org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.executeProduceConsume(ExecuteProduceConsume.java:303)\n\tat org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceConsume(ExecuteProduceConsume.java:148)\n\tat org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:136)\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:671)\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:589)\n\tat java.lang.Thread.run(Thread.java:745)\n",
          "code": 500
        }
      }
      

      This is because in case of DateField any parse exception is wrapped in SolrException with code set to 400
      https://github.com/apache/lucene-solr/blob/branch_6_5/solr/core/src/java/org/apache/solr/util/DateMathParser.java#L240

      But in case of Integer, Long, Double and some other field types, Parse exception are not handled separately hence any exception in this case would be propagated.

      Possible approaches

      • Handle any such parse exception in RequestHandlerBase (handleRequest method) just like SyntaxError
      • Wrap such exceptions in SolrException (just like how it is handled in DateField and LatLonField)

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              munendrasn Munendra S N
              Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: