Example #1
0
        public override void OnException(ExceptionContext context)
        {
            Exception ex            = context.Exception;
            string    correlationId = context.HttpContext.GetCorrelationId();

            IActionResult     result;
            ExceptionContract errorData;

            if (ex is BusinessLogicException businessLogicException)
            {
                errorData = new ExceptionContract(businessLogicException, correlationId);
                if (ex is EntityNotFoundException)
                {
                    result = new NotFoundObjectResult(errorData);
                }
                else
                {
                    result = new BadRequestObjectResult(errorData);
                }
            }
            else
            {
                errorData = new ExceptionContract(DEFAULT_ERROR_MESSAGE, DEFAULT_ERROR_CODE, correlationId);
                result    = new ObjectResult(errorData)
                {
                    StatusCode = StatusCodes.Status500InternalServerError
                };
            }

            context.Result = result;
        }
Example #2
0
        public async Task OnExceptionAsync(ExceptionContext context)
        {
            try
            {
                var exception = new ExceptionContract
                {
                    Method    = context.HttpContext.Request.Method,
                    Path      = context.HttpContext.Request.Path,
                    IpAddress =
                        $"{context.HttpContext.Connection.LocalIpAddress} {context.HttpContext.Connection.RemoteIpAddress}",
                    Time    = DateTime.Now,
                    Message = context.Exception.Message,
                };

                await _manager.Log(exception);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
            }
        }
Example #3
0
        public async Task DeploymentException()
        {
            ContractExecutionException exec = null;

            try
            {
                await ExceptionContract.New(_throwOnConstructor : true, RpcClient);
            }
            catch (ContractExecutionException ex)
            {
                exec = ex;
            }

            var expected = @"
INVALID instruction hit!
-> at 'assert(!_throwOnConstructor);' in 'ExceptionContract' constructor in file 'ExceptionContract.sol' : line 8";

            Assert.AreEqual(
                StringUtil.NormalizeNewLines(expected).Trim(),
                StringUtil.NormalizeNewLines(exec.Message).Trim());
        }
Example #4
0
 protected override async Task BeforeEach()
 {
     // Deploy our test contract
     _contract = await ExceptionContract.New(_throwOnConstructor : false, RpcClient);
 }
 public async Task ExpectDeploymentRevert_Fail()
 {
     await Assert.ThrowsExceptionAsync <Exception>(() => ExceptionContract.New(_throwOnConstructor : false, RpcClient).ExpectRevert());
 }
 public async Task ExpectDeploymentRevert()
 {
     await ExceptionContract.New(_throwOnConstructor : true, RpcClient).ExpectRevert();
 }