protected async Task ProcessRequest()

in Libraries/src/Amazon.Lambda.AspNetCoreServer/AbstractAspNetCoreFunction.cs [499:573]


        protected async Task<TRESPONSE> ProcessRequest(ILambdaContext lambdaContext, object context, InvokeFeatures features, bool rethrowUnhandledError = false)
        {
            var defaultStatusCode = 200;
            Exception ex = null;
            try
            {
                try
                {
                    await this._server.Application.ProcessRequestAsync(context);
                }
                catch (AggregateException agex)
                {
                    ex = agex;
                    _logger.LogError(agex, $"Caught AggregateException: '{agex}'");
                    var sb = new StringBuilder();
                    foreach (var newEx in agex.InnerExceptions)
                    {
                        sb.AppendLine(this.ErrorReport(newEx));
                    }

                    _logger.LogError(sb.ToString());
                    ((IHttpResponseFeature)features).StatusCode = 500;
                }
                catch (ReflectionTypeLoadException rex)
                {
                    ex = rex;
                    _logger.LogError(rex, $"Caught ReflectionTypeLoadException: '{rex}'");
                    var sb = new StringBuilder();
                    foreach (var loaderException in rex.LoaderExceptions)
                    {
                        var fileNotFoundException = loaderException as FileNotFoundException;
                        if (fileNotFoundException != null && !string.IsNullOrEmpty(fileNotFoundException.FileName))
                        {
                            sb.AppendLine($"Missing file: {fileNotFoundException.FileName}");
                        }
                        else
                        {
                            sb.AppendLine(this.ErrorReport(loaderException));
                        }
                    }

                    _logger.LogError(sb.ToString());
                    ((IHttpResponseFeature)features).StatusCode = 500;
                }
                catch (Exception e)
                {
                    ex = e;
                    if (rethrowUnhandledError) throw;
                    _logger.LogError(e, $"Unknown error responding to request: {this.ErrorReport(e)}");
                    ((IHttpResponseFeature)features).StatusCode = 500;
                }

                if (features.ResponseStartingEvents != null)
                {
                    await features.ResponseStartingEvents.ExecuteAsync();
                }
                var response = this.MarshallResponse(features, lambdaContext, defaultStatusCode);

                if (ex != null && IncludeUnhandledExceptionDetailInResponse)
                {
                    InternalCustomResponseExceptionHandling(response, lambdaContext, ex);
                }

                if (features.ResponseCompletedEvents != null)
                {
                    await features.ResponseCompletedEvents.ExecuteAsync();
                }

                return response;
            }
            finally
            {
                this._server.Application.DisposeContext(context, ex);
            }
        }