Coveo for Sitecore 5 is now available!

Internal Server Error When Querying the REST Service

Symptoms

  1. When performing a query in the JavaScript Search UI, you may see the following error: Oops! Something went wrong on the server.

  2. When examining the network transactions on the JavaScript Search UI page using a tool similar to Chrome Developer Tools, you may see an HTTP error 500 (Internal Server Error):

  3. When looking at the response of the erroneous request, you may see the following error message:

     Server Error in '/' Application.
     Object reference not set to an instance of an object.
     Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
     Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
     Source Error:
     An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
     Stack Trace: 
     [NullReferenceException: Object reference not set to an instance of an object.]
        Coveo.Framework.Databases.DatabaseWrapper..ctor(Database p_Database) +77
        Coveo.Framework.Utils.SitecoreContextWrapper.GetCurrentDatabase() +121
        Coveo.UI.Helpers.SitecoreHelper.GetSearchIndex() +412
        Coveo.SearchProvider.Rest.SitecoreRestHttpHandler.GetSecurityProviderName() +178
        Coveo.SearchProvider.Rest.SitecoreRestHttpHandler.OnInitializeSettings() +1030
        Coveo.Search.Api.Proxy.ProxyHttpHandler.OnInitialize() +57
        Coveo.Search.Api.Proxy.ProxyHttpHandler.EnsureInitialized() +139
        Coveo.Search.Api.Proxy.ProxyHttpHandler.ProcessRequest(HttpContext context) +77
        System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +912
        System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +164
    

Causes

This issue may occur:

  1. When upgrading a Sitecore instance, into which a .Net search interface was integrated, to using Coveo for Sitecore. In the .Net search interface integration guide, it is recommended to setup Sitecore to ignore the /coveo url prefix to resolve a resource loading issue. In Coveo for Sitecore, however, HTTP requests made to /coveo/rest must be handled by Sitecore to ensure that the Sitecore context is available in the requests.
  2. When integrating Coveo for Sitecore in a Sitecore instance which has its Sitecore.Pipelines.HttpRequest.ItemResolver processor removed from the httpRequestBegin pipeline. Coveo for Sitecore uses this processor in a configuration patch file to insert another processor just before. If the Sitecore.Pipelines.HttpRequest.ItemResolver processor is missing, Coveo for Sitecore will not be able to patch the configuration correctly.

Resolution

  1. To fix this issue, remove the URL prefixes that start with /coveo in the IgnoreUrlPrefixes setting XML element in the Sitecore web.config file.

    Example:

     <setting name="IgnoreUrlPrefixes" value="/sitecore/default.aspx|/trace.axd|/webresource.axd"/>
    
  2. To fix this issue:

    1. Run the showconfig.aspx page.
    2. Identify the type (including the assembly) of the processor that replaced the original Sitecore.Pipelines.HttpRequest.ItemResolver processor.
    3. Edit the Coveo.SearchProvider.Rest.config file.
    4. Find this line:

       <processor patch:before="processor[@type = 'Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel']" type="Coveo.SearchProvider.Rest.Processors.HttpRequestBegin.TransferCoveoRestSearchRequest, Coveo.SearchProvider.Rest" />
      
    5. Replace it with this line:

       <processor patch:before="processor[@type = 'Type of the processor that replaced the original ItemResolver processor']" type="Coveo.SearchProvider.Rest.Processors.HttpRequestBegin.TransferCoveoRestSearchRequest, Coveo.SearchProvider.Rest" />
      
    6. Save the file.