Exemplo n.º 1
0
        public override void OnException(ExceptionContext context)
        {
            var exception = context.Exception;

            Console.WriteLine($"Message : {exception.Message}\nStackTrace : {exception.StackTrace}");

            if (exception.GetType().IsSubclassOf(typeof(CustomException)))
            {
                var customException = (CustomException)exception;
                context.Result = customException.Code == ErrorCode.NotModifiedException
                    ? ApiResponder.RespondStatusCode(HttpStatusCode.NotModified)
                    : ApiResponder.RespondHandledError(exception.Message, ((CustomException)exception).Code);
            }
            else
            {
                context.Result = ApiResponder.RespondUnhandledError(exception.Message, ErrorCode.UnknownException);
            }
        }