public async Task InvokeAsync(HttpContext context) { context.Response.StatusCode = _statusCode; FulcrumException fulcrumException = null; if (_statusCode >= 500) { fulcrumException = new FulcrumAssertionFailedException("Internal error message"); } else if (_statusCode >= 400) { fulcrumException = new FulcrumServiceContractException("Client error message"); } if (_statusCode >= 400) { await context.Response.WriteAsync("Test"); context.Response.Body = new MemoryStream(); context.Response.ContentType = "application/json"; var fulcrumError = ExceptionConverter.ToFulcrumError(fulcrumException); var content = ExceptionConverter.ToJsonString(fulcrumError, Formatting.Indented); await context.Response.WriteAsync(content); } }
private Ticket GetTicketWithExceptions(string ticketId, ExpectedResultEnum expectedFacadeResult) { FulcrumException fulcrumException = null; switch (expectedFacadeResult) { case ExpectedResultEnum.Ok: return(new Ticket { Id = ticketId }); case ExpectedResultEnum.BusinessRuleException: fulcrumException = new BusinessRuleException("Business rule exception"); break; case ExpectedResultEnum.ConflictException: fulcrumException = new ConflictException("Conflict exception"); break; case ExpectedResultEnum.ServerContractException: fulcrumException = new ServerContractException("Contract exception"); break; case ExpectedResultEnum.NotFoundException: fulcrumException = new NotFoundException("Not found exception"); break; case ExpectedResultEnum.UnauthorizedException: fulcrumException = new UnauthorizedException("Unauthorized exception"); break; case ExpectedResultEnum.AssertionFailedException: fulcrumException = new AssertionFailedException("Assertion failed exception"); break; case ExpectedResultEnum.NotImplementedException: fulcrumException = new NotImplementedException("Not implemented exception"); break; case ExpectedResultEnum.TryAgainException: fulcrumException = new TryAgainException("Try again exception"); break; default: fulcrumException = new AssertionFailedException($"Unexpected switch value: {expectedFacadeResult}"); break; } // This is to be able to test that the properties are copied all the way back to the test case. fulcrumException.Code = fulcrumException.InstanceId; throw fulcrumException; }
public static FulcrumException FromBllToServer(FulcrumException source) { if (source == null) { return(null); } switch (source.TypeId) { case ContractException.ExceptionTypeId: return(new AssertionFailedException($"Unexpected error: {source.Message}", source)); default: return(source); } }
public static FulcrumException FromDalToBll(FulcrumException source, string serverTechnicalName) { if (source == null) { return(null); } switch (source.TypeId) { case AssertionFailedException.ExceptionTypeId: case NotImplementedException.ExceptionTypeId: return(new AssertionFailedException($"Did not expect {serverTechnicalName ?? "server"} to return the following error: {source.Message}", source)); case ServerContractException.ExceptionTypeId: return(new AssertionFailedException($"Bad call to { serverTechnicalName ?? "Server" }: { source.Message}", source)); case UnauthorizedException.ExceptionTypeId: return(new AssertionFailedException($"Unauthorized call to {serverTechnicalName ?? "server"}: {source.Message}", source)); default: source.ServerTechnicalName = serverTechnicalName; return(source); } }
/// <summary> /// Convert an exception (<paramref name="fulcrumException"/>) into a <see cref="FulcrumError"/>. /// </summary> public static FulcrumError ToFulcrumError(FulcrumException fulcrumException) { return(ToFulcrumError(fulcrumException, true)); }
/// <summary> /// Checks a dictionary for the proper <see cref="HttpStatusCode"/> for <paramref name="fulcrumException"/>. /// </summary> public static HttpStatusCode?ToHttpStatusCode(FulcrumException fulcrumException) { var error = ToFulcrumError(fulcrumException); return(ToHttpStatusCode(error)); }