Exemplo n.º 1
0
        public ProxyException(ErrorResponse errorResponse)
            : base()
        {
            ErrorResponse = errorResponse;

            StringBuilder message = new StringBuilder();

            message
                .AppendLine("An unhandled exception ocurred in the remote api.")
                .AppendLine(errorResponse.ToString());

            _message = message.ToString();
        }
        public override void OnException(HttpActionExecutedContext actionExecutedContext)
        {
            if (actionExecutedContext == null)
                throw new ArgumentNullException("actionExecutedContext");

            var exception = actionExecutedContext.Exception;
            var correlationId = actionExecutedContext.Request.GetCorrelationId().ToString();

            var errorResponse = new ErrorResponse(correlationId);
            errorResponse.Message = exception.Message;
            errorResponse.Exception = exception.ToString();
            errorResponse.DetailsUrl = "/api/{api_version}/error/";
            errorResponse.Ack = AckType.FAILURE;

            actionExecutedContext.Response =
                actionExecutedContext.Request.CreateResponse(HttpStatusCode.InternalServerError, errorResponse);
        }
        public override void Handle(ExceptionHandlerContext context)
        {
            if (context == null) {
                throw new ArgumentNullException("context");
            }

            var exception = context.Exception;
            var correlationId = context.Request.GetCorrelationId().ToString();

            var errorResponse = new ErrorResponse(correlationId);
            errorResponse.Message = exception.Message;
            errorResponse.Exception = exception.ToString();
            errorResponse.DetailsUrl = "/api/{api_version}/error/";
            errorResponse.Ack = AckType.FAILURE;

            var response = context.Request.CreateResponse(HttpStatusCode.InternalServerError, errorResponse);

            context.Result = new ResponseMessageResult(response);
        }