Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Log actual errors instead of, well, not
Browse files Browse the repository at this point in the history
  • Loading branch information
shana committed Sep 12, 2016
1 parent 8448a3b commit 67f7b3e
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions src/GitHub.App/Models/RepositoryHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ public IObservable<AuthenticationResult> LogIn(string usernameOrEmail, string pa
.SelectMany(_ => GetUserFromApi())
.Catch<UserAndScopes, ApiException>(firstTryEx =>
{
LogError(firstTryEx, usernameOrEmail);
var exception = firstTryEx as AuthorizationException;
if (isEnterprise
&& exception != null
Expand Down Expand Up @@ -201,6 +203,31 @@ public IObservable<AuthenticationResult> LogIn(string usernameOrEmail, string pa
.PublishAsync();
}

void LogError(ApiException ex, string usernameOrEmail)
{
var msg = ex.Message;
var apiex = ex as AuthorizationException;
if (apiex != null)
{
msg += Environment.NewLine;
msg += apiex.ApiError.Message;
if (apiex.ApiError.Errors != null)
{
foreach (var err in apiex.ApiError.Errors)
{
msg += Environment.NewLine;
msg += err.Message;
}
}
}
log.Info(CultureInfo.InvariantCulture, "Log in to {0} host '{1}' with username '{2}': {3}",
Address.WebUri.Host,
Address.ApiUri,
usernameOrEmail,
msg
);
}

public IObservable<Unit> LogOut()
{
if (!IsLoggedIn) return Observable.Return(Unit.Default);
Expand Down Expand Up @@ -260,11 +287,6 @@ IObservable<AuthenticationResult> LoginWithApiUser(UserAndScopes userAndScopes)
SupportsGist = userAndScopes.Scopes?.Contains("gist") ?? true;
IsLoggedIn = true;
}
log.Info("Log in from cache for login '{0}' to host '{1}' {2}",
userAndScopes?.User?.Login ?? "(null)",
hostAddress.ApiUri,
result.IsSuccess() ? "SUCCEEDED" : "FAILED");
});
}

Expand Down

0 comments on commit 67f7b3e

Please sign in to comment.