Ejemplo n.º 1
0
        /// <summary>
        /// Handles the exception.
        /// </summary>
        /// <returns></returns>
        public HandledResponseModel HandleException()
        {
            var response = new HandledResponseModel();

            TypeSwitch.Eval(Exception,

                            TypeSwitch.Case <HandledException>(ex =>
            {
                response = new HandledResponseModel()
                {
                    StatusCode = (int)ex.StatusCode,
                    Descriptor = BadRequestDescriptor,
                    Exceptions = ToExResponse(ex)
                };
            }),

                            TypeSwitch.Case <HandledExceptionCollection>((ex) =>
            {
                response = new HandledResponseModel()
                {
                    StatusCode = (int)ex.StatusCode,
                    Descriptor = BadRequestDescriptor,
                    Exceptions = ToExResponse(ex)
                };
            }),

                            TypeSwitch.Case <Exception>((ex) =>
            {
                response = new HandledResponseModel()
                {
                    StatusCode = (int)HttpStatusCode.InternalServerError,
                    Descriptor = BadRequestDescriptor,
                    Exceptions = ToExResponse(ex)
                };
            }),

                            TypeSwitch.Default(() => { })

                            );

            return(response);
        }