Try our conversational search powered by Generative AI!

Episerver Content Delivery API - 500 Internal server error

Vote:
 

Hello,

I tried to add follwoing nuget packges in an existing project (Dev environment).

1) EPiServer.ContentDeliveryApi 

2) EPiServer.ContentDeliveryApi.Search

I am receving 500 Internal Server error when I try to run the site.

Can anyone please help me out here?

#224973
Jul 01, 2020 8:30
Vote:
 

Hi, to anyone to be able to help you more information would be needed.

What is the actual error you get, 500 Internal Server error is just the common HTTP status code that something failed on server side.

In any case paste the actual Exception here that happens on your server (look at log(s) or if you get some info in the actual request that returns the 500, in your dev you can always disable the custom errors to be able to see the details of the error (if you have used a custom 500 page or you have some programmatic handling on server - all depends on your project)

#225055
Jul 03, 2020 17:17
Vote:
 

Hi, the problem when encountering 500 errors from Content Delivery API requests is that something in the API catches the actual error and just outputs a generic message in the JSON result:

{"error":{"code":"InternalServerError","message":"The server encountered an internal error or misconfiguration","target":null,"details":[]}}

This is in a CMS 11 (Content Delivery API 2.21.1) environment, with custom error pages turned off. (With “<httpErrors errorMode="Detailed"/>” and “<customErrors mode="Off">”.) The logs also just display the numeric “500” error code.

Also, this only affects some content items. Many content items return the expected data just fine. Thus, I would like to know exactly what it is in each failing content item that causes exceptions, which with this limited amount of information is very hard to guess.

Is there any easy way of configuring the API to include an actual error message and stack trace in a development environment?

#298767
Edited, Mar 22, 2023 11:02
Vote:
 

What does your log say?

#298768
Mar 22, 2023 11:19
Vote:
 

Hi Eric, thank you for your reply! I turns out that log4net in our dev environment was misconfigured and did not write any error logs. In the stage environment we do get logged errors of the following kind, with an appended stack trace. Thanks for prompting us to double-check the logging setup.

2023-03-22 16:10:41,747 [73] ERROR EPiServer.ContentApi.Cms.Controllers.ContentApiController: Error occurred during Content Api Request
#298772
Mar 22, 2023 15:23
jedreqq - Mar 24, 2023 9:01
Hi Otto,
Did you find out possible solution for fixing this type of an error? I am having similar issues with implementing the contentdeliveryapi forms package for a few days now
Vote:
 

Try to increase the verbosity of the log, see what happens before and after the error as well.

#298776
Mar 22, 2023 20:47
Vote:
 

Hi Eric, Otto,
I think I am having similar issue and the extended error log for this issue is 

2023-03-24 10:27:48,803 [143] ERROR EPiServer.ContentApi.Cms.Controllers.ContentApiController: Error occurred during Content Api Request
System.NullReferenceException: Object reference not set to an instance of an object.
   at EPiServer.Forms.Controllers.FormContainerBlockController.Index(FormContainerBlock currentBlock)
   at EPiServer.ContentApi.Forms.FormRenderingService.BuildFormTemplate(IFormContainerBlock formContainerBlock)
   at EPiServer.ContentApi.Forms.FormContentModelMapper.Convert(IContent content, ConverterContext converterContext)
   at MusicFestival.Template.Models.ExtendedContentModelMapper.TransformContent(IContent content, Boolean excludePersonalizedContent, String expand) in C:\mfvue\musicfestival-vue-template\src\MusicFestival.Vue.Template\Models\ExtendedContentModelMapper.cs:line 44
   at EPiServer.ContentApi.Core.Serialization.ContentConvertingService.ConvertToContentApiModel(IContent content, ConverterContext converterContext)
   at EPiServer.ContentApi.Core.Serialization.ContentConvertingService.Convert(IContent content, ConverterContext converterContext)
   at EPiServer.ContentApi.Cms.Controllers.ContentApiController.ResultFromContent(IContent content, String expand, String select, Boolean addMetadataHeaders, ContextMode contextMode, SiteDefinition site, String remainingRoute, String language)
   at EPiServer.ContentApi.Cms.Controllers.ContentApiController.Get(String contentReference, List`1 languages, String expand, String select)
System.NullReferenceException: Object reference not set to an instance of an object.
   at EPiServer.Forms.Controllers.FormContainerBlockController.Index(FormContainerBlock currentBlock)
   at EPiServer.ContentApi.Forms.FormRenderingService.BuildFormTemplate(IFormContainerBlock formContainerBlock)
   at EPiServer.ContentApi.Forms.FormContentModelMapper.Convert(IContent content, ConverterContext converterContext)
   at MusicFestival.Template.Models.ExtendedContentModelMapper.TransformContent(IContent content, Boolean excludePersonalizedContent, String expand) in C:\mfvue\musicfestival-vue-template\src\MusicFestival.Vue.Template\Models\ExtendedContentModelMapper.cs:line 44
   at EPiServer.ContentApi.Core.Serialization.ContentConvertingService.ConvertToContentApiModel(IContent content, ConverterContext converterContext)
   at EPiServer.ContentApi.Core.Serialization.ContentConvertingService.Convert(IContent content, ConverterContext converterContext)
   at EPiServer.ContentApi.Cms.Controllers.ContentApiController.ResultFromContent(IContent content, String expand, String select, Boolean addMetadataHeaders, ContextMode contextMode, SiteDefinition site, String remainingRoute, String language)
   at EPiServer.ContentApi.Cms.Controllers.ContentApiController.Get(String contentReference, List`1 languages, String expand, String select)


I tried to debug the 44 line in ExtendedContentModelMapper but I cannot detect what is exactly missing in this line:

var contentModel = _defaultContentModelMapper.TransformContent(content, excludePersonalizedContent, expand);

Did you come across this one?

#298908
Mar 24, 2023 9:34
Vote:
 

@jedreqq interesting, I typically inherit Extendedmapprs from ContentModelMapperBase. E.g

public class ExtendedContentModelMapper : ContentModelMapperBase 
{
    public override ContentApiModel TransformContent(IContent content, bool excludePersonalizedContent, string expand)
    {
        var contentModel = base.TransformContent(content, excludePersonalizedContent, expand);

        // code        
    }
}

Anyway, in your case it apperas as if you have content errors in a form block. ContentDelivery will crash in such cases. You can probably chase that down by looking at the icontent object.

#298912
Mar 24, 2023 11:16
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.