Internal Server Error When Querying the REST Service
Internal Server Error When Querying the REST Service
Symptoms
-
When performing a query in the JavaScript Search UI, you may see the following error:
Oops! Something went wrong on the server.
-
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):
-
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:
-
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, we recommend that you 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. -
When integrating Coveo for Sitecore in a Sitecore instance which has its
Sitecore.Pipelines.HttpRequest.ItemResolver
processor removed from thehttpRequestBegin
pipeline. Coveo for Sitecore uses this processor in a configuration patch file to insert another processor just before. If theSitecore.Pipelines.HttpRequest.ItemResolver
processor is missing, Coveo for Sitecore won’t be able to patch the configuration correctly.
Resolution
-
To fix this issue, remove the URL prefixes that start with
/coveo
in theIgnoreUrlPrefixes
setting XML element in the Sitecoreweb.config
file.Example:
<setting name="IgnoreUrlPrefixes" value="/sitecore/default.aspx|/trace.axd|/webresource.axd"/>
-
To fix this issue:
-
Run the
showconfig.aspx
page. -
Identify the type (including the assembly) of the processor that replaced the original
Sitecore.Pipelines.HttpRequest.ItemResolver
processor. -
Edit the
Coveo.SearchProvider.Rest.config
file. -
Find this line:
<processor patch:before="processor[@type = 'Sitecore.Pipelines.HttpRequest.ItemResolver, Sitecore.Kernel']" type="Coveo.SearchProvider.Rest.Processors.HttpRequestBegin.TransferCoveoRestSearchRequest, Coveo.SearchProvider.Rest" />
-
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" />
-
Save the file.
-