Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
This type of error should be easier to troubleshoot if you debug and uncheck "Enable Just My Code". Otherwise you're welcome to contact our developer support service for further assistance
Hi Forum
We are updating Commerce inventory through the Service API. In general, we are seeing good enough performance using the Service API, so we haven't found the need to implement any other method for updating inventory from an external source.
However we are seeing a lot of NullReferenceExceptions in the log. We expect that they come because we try to update inventory for a Warehouse that doesn't exist in Optimizely Commerce.
I guess we could send better data, but data quality is not always something we are in control of. However I don't like that Optimizely throws a NullReferenceException and returns HTTP 500. I would rather have Optimizely handle this situation internally and send a better HTTP response code indicating that something is wrong. And perhaps send a message with an explanation of what is wrong :)
Is this something that, somebody from Optimizely can take a look at?
Right now, we just ignore any HTTP 500 from this API. But we are concerned that some other error may occur that we misses because we ignore all HTTP 500's.
Log statements below.
2025-02-14 14:56:12.911 +01:00 [INF] Executing endpoint 'EPiServer.ServiceApi.Commerce.Controllers.Catalog.WarehouseInventoryController.PostCatalogEntryWarehouseInventory (EPiServer.ServiceApi.Commerce)'
2025-02-14 14:56:12.911 +01:00 [INF] Route matched with {action = "PostCatalogEntryWarehouseInventory", controller = "WarehouseInventory", area = "", page = ""}. Executing controller action with signature Microsoft.AspNetCore.Mvc.IActionResult PostCatalogEntryWarehouseInventory(System.String, EPiServer.ServiceApi.Commerce.Models.Catalog.WarehouseInventory) on controller EPiServer.ServiceApi.Commerce.Controllers.Catalog.WarehouseInventoryController (EPiServer.ServiceApi.Commerce).
2025-02-14 14:56:12.912 +01:00 [INF] POST request to PostCatalogEntryWarehouseInventory from ::1, Parameters: 7344M1215034190, EPiServer.ServiceApi.Commerce.Models.Catalog.WarehouseInventory, Headers: Host:localhost:5000, Content-Type:application/json; charset=utf-8, Cookie:EPiServer_Commerce_AnonymousId=16692f39-b7aa-4f06-badd-1fa6e77c9ffc; Language=da-DK; EPiStateMarker=true; .AspNetCore.Session=CfDJ8LdV3BqZlPJJp7sojRD%2F4hGGZW2Ytw31Z2E8TeRv6tQpUtCyTUjEnmWswCK60Y1liKT%2FkDktJx6td0x256FGihn7Tpj%2F34okGNB3Ot1OB29tvHK2TaNk%2Bij8WJy3N1b%2FzbWe9qGWa36BBZ0n5mZf0QlQKLThDOhvhjrArzZK9UAd, Request-Id:|842365c89c77e23524ee411cad0ac4e9.343799475b8f47d1., traceparent:00-842365c89c77e23524ee411cad0ac4e9-343799475b8f47d1-00, Content-Length:412.
2025-02-14 14:56:13.105 +01:00 [INF] Executing action method EPiServer.ServiceApi.Commerce.Controllers.Catalog.WarehouseInventoryController.PostCatalogEntryWarehouseInventory (EPiServer.ServiceApi.Commerce) - Validation state: "Valid"
2025-02-14 14:56:13.109 +01:00 [INF] Executed action EPiServer.ServiceApi.Commerce.Controllers.Catalog.WarehouseInventoryController.PostCatalogEntryWarehouseInventory (EPiServer.ServiceApi.Commerce) in 197.8718ms
2025-02-14 14:56:13.110 +01:00 [INF] Executed endpoint 'EPiServer.ServiceApi.Commerce.Controllers.Catalog.WarehouseInventoryController.PostCatalogEntryWarehouseInventory (EPiServer.ServiceApi.Commerce)'
2025-02-14 14:56:14.915 +01:00 [ERR] An unhandled exception has occurred while executing the request.
System.NullReferenceException: Object reference not set to an instance of an object.
at EPiServer.ServiceApi.Commerce.Controllers.Catalog.Construction.WarehouseInventoryModelFactory.MapWarehouseInventory(InventoryRecord inventoryRecord)
at EPiServer.ServiceApi.Commerce.Controllers.Catalog.WarehouseInventoryController.PostCatalogEntryWarehouseInventory(String entryCode, WarehouseInventory warehouseInventory)
at lambda_method1357(Closure, Object, Object[])
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Logged|12_1(ControllerActionInvoker invoker)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ExceptionContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeNextResourceFilter()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|7_0(Endpoint endpoint, Task requestTask, ILogger logger)
at NDI.Website.Core.Session.CurrentContextMiddleware.InvokeAsync(HttpContext context) in C:\Source\NDI\NDI.Website\NDI.Website\Core\Session\CurrentContextMiddleware.cs:line 86
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
at Mediachase.Commerce.Anonymous.Internal.AnonymousIdMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
Thank you for your help.
Regards
Anders Kåre Olsen