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; }
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); } }
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()); }
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(); }