WebApi icon indicating copy to clipboard operation
WebApi copied to clipboard

EDM model exception of OData not caught in global exception handler

Open gohilravi opened this issue 3 years ago • 8 comments

Short summary (3-5 sentences) describing the issue. When providing the wrong input parameter in the OData function i.e. string instead of integer then ODataException is thrown which is not caught in the global exception handler and below error is returned: Microsoft.OData.ODataException: The parameter value ($234) from request is not valid. The parameter value should be format of type 'Edm.Int64'. ---> Microsoft.OData.ODataException: Expected literal type token but found token '$234'. at Microsoft.OData.UriParser.ExpressionLexerLiteralExtensions.ReadLiteralToken(ExpressionLexer expressionLexer) at Microsoft.OData.ODataUriUtils.ConvertFromUriLiteral(String value, ODataVersion version, IEdmModel model, IEdmTypeReference typeReference) at Microsoft.AspNetCore.OData.Routing.Template.SegmentTemplateHelpers.Match(ODataTemplateTranslateContext context, IEdmFunction function, IDictionary'2 parameterMappings) --- End of inner exception stack trace --- at Microsoft.AspNetCore.OData.Routing.Template.SegmentTemplateHelpers.Match(ODataTemplateTranslateContext context, IEdmFunction function, IDictionary' parameterMappings) at Microsoft.AspNetCore.OData.Routing.Template.FunctionSegmentTemplate.TryTranslate(ODataTemplateTranslateContext context) at Microsoft.AspNetCore.OData.Routing.Template.DefaultODataTemplateTranslator.Translate(ODataPathTemplate path, ODataTemplateTranslateContext context) at Microsoft.AspNetCore.OData.Routing.ODataRoutingMatcherPolicy.ApplyAsync(HttpContext httpContext, CandidateSet candidates) at Microsoft.AspNetCore.Routing.Matching.DfaMatcher.SelectEndpointWithPoliciesAsync(HttpContext httpContext, IEndpointSelectorPolicy[] policies, CandidateSet candidateSet) at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.<Invoke>g__AwaitMatch|8_1(EndpointRoutingMiddleware middleware, HttpContext httpContext, Task matchTask) at Serilog.AspNetCore.RequestLoggingMiddleware.Invoke(HttpContext httpContext) at CorrelationId.CorrelationIdMiddleware.Invoke(HttpContext context, ICorrelationContextFactory correlationContextFactory) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

Assemblies affected

Microsoft.OData 8.0.6 NuGet package

Reproduce steps

Attached screenshot of the issue. OData exception

Expected result

The exception should be handled in the global exception handler.

Actual result

The exception is not being handled in the global exception handler.

Additional detail

  • When providing an invalid value like providing $234 instead of long value 234 in the request parameter id then OData exception is thrown which is not caught in the global exception handler.

gohilravi avatar Jan 21 '22 09:01 gohilravi

Hi @gohilravi thank you for reporting this. Could you share more info about your implementation, and in particular, what you global exception handler looks like?

habbes avatar Jan 25 '22 18:01 habbes

Hi @gohilravi thank you for reporting this. Could you share more info about your implementation, and in particular, what you global exception handler looks like?

Hi @habbes it is a simple exception handler as suggested by the .NET core. Attached global exception handler registration logic and its logic with you.

middleware Registration of middleware

gohilravi avatar Jan 28 '22 13:01 gohilravi

@habbes Did you get a chance to review the previous comment?

amkansara avatar May 05 '22 08:05 amkansara

Any update on this? Seems to be a common issue, especially with folks that have QA testers that send in all kinds of data in testing.

timschwallie avatar Sep 30 '22 15:09 timschwallie

We are seeing the same issue in Microsoft.OData 8.0.10 NuGet package. Any updates on this? Looks like this is a common issue in the OData library.

xubinzheng avatar Sep 30 '22 18:09 xubinzheng

@habbes Do you have any update on this issue? It appears to be quite common. We are still seeing this issue as well. Do you have an estimate or update on a solution?

rcefalu10 avatar Apr 21 '23 21:04 rcefalu10

@habbes Any update on this?

nisarg-marutitechlabs avatar Jul 18 '23 14:07 nisarg-marutitechlabs

@gohilravi Any update on your issue? Did you manage to solve it?

velchev avatar Nov 24 '23 09:11 velchev