Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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