/// <summary> /// Constructs an instance of ApiException /// </summary> /// <param name="innerException">The inner exception</param> protected ApiException(ApiException innerException) { Ensure.ArgumentNotNull(innerException, "innerException"); StatusCode = innerException.StatusCode; ApiError = innerException.ApiError; }
/// <summary> /// Constructs an instance of TwoFactorChallengeFailedException /// </summary> /// <param name="authorizationCode">The authorization code that was incorrect</param> /// <param name="innerException">The inner exception</param> public TwoFactorChallengeFailedException( string authorizationCode, ApiException innerException) : base(ParseTwoFactorType(innerException), innerException) { AuthorizationCode = authorizationCode; }
public async Task ReturnsExistsForApiExceptionWithCorrectHeaders() { var httpClient = Substitute.For<IHttpClient>(); var response = Substitute.For<IResponse>(); response.Headers["Server"].Returns("GitHub.com"); response.Headers.ContainsKey("X-GitHub-Request-Id").Returns(true); var apiException = new ApiException(response); httpClient.Send(Args.Request, CancellationToken.None).ThrowsAsync(apiException); var productHeader = new ProductHeaderValue("GHfW", "99"); var enterpriseProbe = new EnterpriseProbe(productHeader, httpClient); var result = await enterpriseProbe.Probe(new Uri("https://example.com/")); Assert.Equal(EnterpriseProbeResult.Ok, result); }
static TwoFactorType ParseTwoFactorType(ApiException exception) { return exception == null ? TwoFactorType.None : Connection.ParseTwoFactorType(exception.HttpResponse); }
protected ApiException(ApiException innerException) { Ensure.ArgumentNotNull(innerException, "innerException"); StatusCode = innerException.StatusCode; ApiError = innerException.ApiError; }
/// <summary> /// Constructs an instance of the <see cref="UserIsOrganizationMemberException"/> class. /// </summary> /// <param name="response">The HTTP payload from the server</param> /// <param name="innerException">The inner exception</param> public UserIsOrganizationMemberException(IResponse response, ApiException innerException) : base(response, innerException) { Debug.Assert(response != null && response.StatusCode == (HttpStatusCode)422, "UserIsOrganizationMemberException created with the wrong HTTP status code"); }
/// <summary> /// Constructs an instance of the <see cref="UserIsLastOwnerOfOrganizationException"/> class. /// </summary> /// <param name="response">The HTTP payload from the server</param> /// <param name="innerException">The inner exception</param> public UserIsLastOwnerOfOrganizationException(IResponse response, ApiException innerException) : base(response, innerException) { Debug.Assert(response != null && response.StatusCode == HttpStatusCode.Forbidden, "UserIsLastOwnerOfOrganizationException created with the wrong HTTP status code"); }
/// <summary> /// Constructs an instance of ApiValidationException /// </summary> /// <param name="innerException">The inner exception</param> protected ApiValidationException(ApiException innerException) : base(innerException) { }
static TwoFactorType ParseTwoFactorType(ApiException exception) { return(exception == null ? TwoFactorType.None : Connection.ParseTwoFactorType(exception.HttpResponse)); }
private string FormatApiExceptionForWriting(string message, ApiException ex) { string info = string.Format("{0}, Status: {1}, API Error Msg: {2}", ex.Message, ex.StatusCode, ex.ApiError.Message); return string.Format("{0} {1}: {2}", message, ex.GetType().Name, info); }
public void WritenMessageWithApiExceptionContainsDetailedApiInfo() { var response = new ResponseMock { ResponseUri = new Uri("http://localhost"), StatusCode = HttpStatusCode.NotFound, ContentType = "application/json", Body = "X-GitHub-Request-Id: 111" }; var apiException = new ApiException(response); _log.Write(LogLevel.Info, "Test message", apiException); Assert.That(_log.LastMessageWritten, Does.Contain("ApiException")); Assert.That(_log.LastMessageWritten, Does.Contain("Status: NotFound")); }