internal static Task <bool> HandleResponseWriteException(this Exception originalEx, IRequest request, IResponse response, string defaultContentType)
        {
            HostContext.RaiseAndHandleUncaughtException(request, response, request.OperationName, originalEx);

            if (!HostContext.Config.WriteErrorsToResponse)
            {
                return(originalEx.AsTaskException <bool>());
            }

            var errorMessage = $"Error occured while Processing Request: [{originalEx.GetType().GetOperationName()}] {originalEx.Message}";

            try
            {
                if (!response.IsClosed)
                {
                    response.WriteErrorToResponse(
                        request,
                        defaultContentType ?? request.ResponseContentType,
                        request.OperationName,
                        errorMessage,
                        originalEx,
                        (int)HttpStatusCode.InternalServerError);
                }
            }
            catch (Exception writeErrorEx)
            {
                //Exception in writing to response should not hide the original exception
                Log.Info("Failed to write error to response: {0}", writeErrorEx);
                return(originalEx.AsTaskException <bool>());
            }
            return(TypeConstants.TrueTask);
        }
        protected Task HandleException(IRequest httpReq, IResponse httpRes, string operationName, Exception ex)
        {
            var errorMessage = string.Format("Error occured while Processing Request: {0}", ex.Message);

            Log.Error(errorMessage, ex);

            try
            {
                HostContext.RaiseUncaughtException(httpReq, httpRes, operationName, ex);
                return(EmptyTask);
            }
            catch (Exception writeErrorEx)
            {
                //Exception in writing to response should not hide the original exception
                Log.Info("Failed to write error to response: {0}", writeErrorEx);
                //rethrow the original exception
                return(ex.AsTaskException());
            }
            finally
            {
                httpRes.EndRequest(skipHeaders: true);
            }
        }
Exemple #3
0
        protected Task HandleException(IRequest httpReq, IResponse httpRes, string operationName, Exception ex)
        {
            var errorMessage = $"Error occured while Processing Request: {ex.Message}";

            HostContext.AppHost.OnLogError(typeof(HttpAsyncTaskHandler), errorMessage, ex);

            try
            {
                HostContext.RaiseAndHandleUncaughtException(httpReq, httpRes, operationName, ex);
                return(TypeConstants.EmptyTask);
            }
            catch (Exception writeErrorEx)
            {
                //Exception in writing to response should not hide the original exception
                Log.Info("Failed to write error to response: {0}", writeErrorEx);
                //rethrow the original exception
                return(ex.AsTaskException());
            }
            finally
            {
                httpRes.EndRequest(skipHeaders: true);
            }
        }