コード例 #1
0
        /// <summary>
        /// Invoke Pass through middleware
        /// </summary>
        /// <param name="context"></param>
        /// <param name="next"></param>
        /// <returns></returns>
        public async Task Invoke(FunctionExecutionContext context, FunctionExecutionDelegate next)
        {
            context.Logger?.Log(LogLevel.Information, "Inside pass-through middleware");

            context.InvocationResult = new HttpResponseData(HttpStatusCode.OK);

            var response = context.InvocationResult as HttpResponseData;

            response.Body += "\n Request stage - Pass-through middleware";

            await next.Invoke(context);

            ResponseStage(context);
        }
        /// <summary>
        /// Invoke ExceptionHandler middleware
        /// </summary>
        /// <param name="context"></param>
        /// <param name="next"></param>
        /// <returns></returns>
        public async Task Invoke(FunctionExecutionContext context, FunctionExecutionDelegate next)
        {
            context.Logger?.Log(LogLevel.Information, "Inside ExceptionHandler middleware");

            context.InvocationResult = new HttpResponseData(HttpStatusCode.Unauthorized);

            var response = context.InvocationResult as HttpResponseData;

            response.Body += "\n Request stage - ExceptionHandler middleware";

            try
            {
                await next.Invoke(context);
            }
            catch (Exception ex)
            {
                context.Logger?.Log(LogLevel.Error, "Catched unhandled exceptions: " + ex.Message);

                await Task.CompletedTask;
            }

            ResponseStage(context);
        }