From 42caea5821ff2436f001d83f55e8f45bedf92260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Fri, 4 Nov 2022 14:58:18 +0300 Subject: [PATCH] Log controller and action name on errors --- .../AbpHttpClientProxyServiceConvention.cs | 90 ++++++++++--------- 1 file changed, 49 insertions(+), 41 deletions(-) diff --git a/framework/src/Volo.Abp.Http.Client.Web/Volo/Abp/Http/Client/Web/Conventions/AbpHttpClientProxyServiceConvention.cs b/framework/src/Volo.Abp.Http.Client.Web/Volo/Abp/Http/Client/Web/Conventions/AbpHttpClientProxyServiceConvention.cs index 08dab1fc82..d44a294799 100644 --- a/framework/src/Volo.Abp.Http.Client.Web/Volo/Abp/Http/Client/Web/Conventions/AbpHttpClientProxyServiceConvention.cs +++ b/framework/src/Volo.Abp.Http.Client.Web/Volo/Abp/Http/Client/Web/Conventions/AbpHttpClientProxyServiceConvention.cs @@ -112,60 +112,68 @@ public class AbpHttpClientProxyServiceConvention : AbpServiceConvention protected virtual void ConfigureClientProxySelector(ControllerModel controller, ActionModel action) { - RemoveEmptySelectors(action.Selectors); - - var remoteServiceAtt = ReflectionHelper.GetSingleAttributeOrDefault(action.ActionMethod); - if (remoteServiceAtt != null && !remoteServiceAtt.IsEnabledFor(action.ActionMethod)) + try { - return; - } + RemoveEmptySelectors(action.Selectors); - var actionApiDescriptionModel = FindActionApiDescriptionModel(controller, action); - if (actionApiDescriptionModel == null) - { - Logger.LogWarning($"Could not find ApiDescriptionModel for action: {action.ActionName} in controller: {controller.ControllerName}, May be the generate-proxy.json is not up to date."); - return;; - } - - ControllerWithAttributeRoute.Add(controller); - ActionWithAttributeRoute.Add(action); - - if (!action.Selectors.Any()) - { - var abpServiceSelectorModel = new SelectorModel + var remoteServiceAtt = ReflectionHelper.GetSingleAttributeOrDefault(action.ActionMethod); + if (remoteServiceAtt != null && !remoteServiceAtt.IsEnabledFor(action.ActionMethod)) { - AttributeRouteModel = new AttributeRouteModel(new RouteAttribute(template: actionApiDescriptionModel.Url)), - ActionConstraints = { new HttpMethodActionConstraint(new[] { actionApiDescriptionModel.HttpMethod }) } - }; + return; + } - action.Selectors.Add(abpServiceSelectorModel); - } - else - { - foreach (var selector in action.Selectors) + var actionApiDescriptionModel = FindActionApiDescriptionModel(controller, action); + if (actionApiDescriptionModel == null) { - var httpMethod = selector.ActionConstraints - .OfType() - .FirstOrDefault()? - .HttpMethods? - .FirstOrDefault(); + Logger.LogWarning($"Could not find ApiDescriptionModel for action: {action.ActionName} in controller: {controller.ControllerName}, May be the generate-proxy.json is not up to date."); + return;; + } - if (httpMethod == null) - { - httpMethod = actionApiDescriptionModel.HttpMethod; - } + ControllerWithAttributeRoute.Add(controller); + ActionWithAttributeRoute.Add(action); - if (selector.AttributeRouteModel == null) + if (!action.Selectors.Any()) + { + var abpServiceSelectorModel = new SelectorModel { - selector.AttributeRouteModel = new AttributeRouteModel(new RouteAttribute(template: actionApiDescriptionModel.Url)); - } + AttributeRouteModel = new AttributeRouteModel(new RouteAttribute(template: actionApiDescriptionModel.Url)), + ActionConstraints = { new HttpMethodActionConstraint(new[] { actionApiDescriptionModel.HttpMethod }) } + }; - if (!selector.ActionConstraints.OfType().Any()) + action.Selectors.Add(abpServiceSelectorModel); + } + else + { + foreach (var selector in action.Selectors) { - selector.ActionConstraints.Add(new HttpMethodActionConstraint(new[] { httpMethod })); + var httpMethod = selector.ActionConstraints + .OfType() + .FirstOrDefault()? + .HttpMethods? + .FirstOrDefault(); + + if (httpMethod == null) + { + httpMethod = actionApiDescriptionModel.HttpMethod; + } + + if (selector.AttributeRouteModel == null) + { + selector.AttributeRouteModel = new AttributeRouteModel(new RouteAttribute(template: actionApiDescriptionModel.Url)); + } + + if (!selector.ActionConstraints.OfType().Any()) + { + selector.ActionConstraints.Add(new HttpMethodActionConstraint(new[] { httpMethod })); + } } } } + catch + { + Logger.LogError($"An exception has occured while configuring client proxy selector. Controller: {controller.ControllerName} ({controller.ControllerType.AssemblyQualifiedName}), Action: {action.ActionName}"); + throw; + } } protected virtual void ConfigureClientProxyApiExplorer(ControllerModel controller)