Пример #1
0
 public override void HandleCore(System.Web.Http.ExceptionHandling.ExceptionHandlerContext context)
 {
     context.Result = new GlobalException()
     {
         StatusCode = HttpStatusCode.InternalServerError,
         Message    = string.Format("Internal exception has occured: {0}", context.Exception.Message),
         Request    = context.Request
     };
 }
Пример #2
0
 public override void Handle(System.Web.Http.ExceptionHandling.ExceptionHandlerContext context)
 {
     context.Result = new ErrorResult
     {
         ExceptionManager  = this.exceptionManager,
         PolicyName        = this.policyName,
         Context           = context,
         TrackingIdFetcher = this.trackingIdFetcher
     };
 }
Пример #3
0
        public override void HandleCore(System.Web.Http.ExceptionHandling.ExceptionHandlerContext context)
        {
            var mensagemAdicional = string.Empty;
            IEnumerable <string> idRequisicao;

            if (context.Request.Content != null &&
                context.Request.Content.Headers.TryGetValues("IdRequisicao", out idRequisicao))
            {
                mensagemAdicional = $", por favor informe o código: {string.Join(",", idRequisicao)}";
            }

            context.Result = new GlobalException()
            {
                StatusCode = HttpStatusCode.InternalServerError,
                Message    = $"Oops! Desculpa! Algo deu errado. Entre em contato com [email protected] para que possamos corrigi-lo{mensagemAdicional}",
                Request    = context.Request
            };
        }
Пример #4
0
        public override void Handle(System.Web.Http.ExceptionHandling.ExceptionHandlerContext context)
        {
            System.Net.HttpStatusCode statusCode = System.Net.HttpStatusCode.InternalServerError;
            string message = "";
            string code    = "RAW";


            if (context.Exception is Gale.Exception.GaleException)
            {
                var ex = (context.Exception as Gale.Exception.GaleException);
                message    = ex.Message;
                code       = ex.Code;
                statusCode = ex.StatusCode;
            }
            else if (context.Exception is Gale.Exception.RestException)
            {
                var ex = (context.Exception as Gale.Exception.RestException);
                message    = ex.Message;
                code       = ex.Code;
                statusCode = ex.StatusCode;
            }
            else
            {
                //FORMAT THE UNHANDLEDEXCEPTION TO REST EXCEPTION FORMAT
                code    = context.Exception.GetType().Name;
                message = context.Exception.Message;
            }

            //WRAP THE EXCEPTION IN A STANDAR FORMAT
            context.Result = new System.Web.Http.Results.ResponseMessageResult(new System.Net.Http.HttpResponseMessage()
            {
                ReasonPhrase = code,
                StatusCode   = statusCode,
                Content      = new System.Net.Http.ObjectContent <Gale.Exception.RestException.ErrorContent>(new Gale.Exception.RestException.ErrorContent()
                {
                    error             = code,
                    error_description = message,
                },
                                                                                                             new System.Net.Http.Formatting.JsonMediaTypeFormatter())
            });
        }