Beispiel #1
0
        /// <summary>
        /// Processes the exception.
        /// </summary>
        /// <param name="ex">The exception raised.</param>
        /// <param name="rq">The incoming request.</param>
        /// <param name="responses">The responses.</param>
        protected virtual Task ProcessRequestException(Exception ex, TransmissionPayload rq, List <TransmissionPayload> responses)
        {
            if (Policy.OnProcessRequestExceptionLog)
            {
                Collector?.LogException($"{FriendlyName}/ProcessRequest unhandled exception: {rq.Message.ToKey()}", ex);
            }

            switch (Policy.OnProcessRequestException)
            {
            case ProcessRequestExceptionBehaviour.DoNothing:
                break;

            case ProcessRequestExceptionBehaviour.SignalSuccessAndSend500ErrorResponse:
                rq.SignalSuccess();
                var rs = rq.ToResponse();
                rs.Message.Status            = "500";
                rs.Message.StatusDescription = ex.Message;
                responses.Add(rs);
                break;

            case ProcessRequestExceptionBehaviour.SignalFailAndDoNothing:
                rq.SignalFail();
                break;

            default:
                throw ex;
            }

            return(Task.FromResult(0));
        }
        /// <summary>
        /// This method processes an unhandled payload.
        /// </summary>
        /// <param name="policy">The action policy.</param>
        /// <param name="reason">The unhandled reason.</param>
        /// <param name="payload">The payload.</param>
        protected virtual void ProcessUnhandledPayload(DispatcherUnhandledAction policy
                                                       , DispatcherRequestUnresolvedReason reason
                                                       , TransmissionPayload payload)
        {
            //OK, we have an problem. We log this as an error and get out of here.
            mDataCollection.DispatcherPayloadUnresolved(payload, reason);

            var args = new DispatcherRequestUnresolvedEventArgs(payload, reason, policy);

            //Raise an event for the unresolved wrapper
            mEventsWrapper.OnProcessRequestUnresolved(args);

            //Process the policy. Note this can be changed in the response.
            switch (args.Policy)
            {
            case DispatcherUnhandledAction.Ignore:
                break;

            case DispatcherUnhandledAction.AttemptResponseFailMessage:
                if (!payload.CanRespond())
                {
                    break;
                }

                var response = payload.ToResponse();
                response.Message.StatusSet(501, args.Reason.ToString());
                response.Message.ChannelPriority = -1;
                Dispatch.Process(response);
                //request.IsSuccess = true;
                break;

            case DispatcherUnhandledAction.Exception:
                //request.IsSuccess = true;
                break;
            }
        }