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

Commit 67f7b3e

Browse files
committed
Log actual errors instead of, well, not
1 parent 8448a3b commit 67f7b3e

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

src/GitHub.App/Models/RepositoryHost.cs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ public IObservable<AuthenticationResult> LogIn(string usernameOrEmail, string pa
125125
.SelectMany(_ => GetUserFromApi())
126126
.Catch<UserAndScopes, ApiException>(firstTryEx =>
127127
{
128+
LogError(firstTryEx, usernameOrEmail);
129+
128130
var exception = firstTryEx as AuthorizationException;
129131
if (isEnterprise
130132
&& exception != null
@@ -201,6 +203,31 @@ public IObservable<AuthenticationResult> LogIn(string usernameOrEmail, string pa
201203
.PublishAsync();
202204
}
203205

206+
void LogError(ApiException ex, string usernameOrEmail)
207+
{
208+
var msg = ex.Message;
209+
var apiex = ex as AuthorizationException;
210+
if (apiex != null)
211+
{
212+
msg += Environment.NewLine;
213+
msg += apiex.ApiError.Message;
214+
if (apiex.ApiError.Errors != null)
215+
{
216+
foreach (var err in apiex.ApiError.Errors)
217+
{
218+
msg += Environment.NewLine;
219+
msg += err.Message;
220+
}
221+
}
222+
}
223+
log.Info(CultureInfo.InvariantCulture, "Log in to {0} host '{1}' with username '{2}': {3}",
224+
Address.WebUri.Host,
225+
Address.ApiUri,
226+
usernameOrEmail,
227+
msg
228+
);
229+
}
230+
204231
public IObservable<Unit> LogOut()
205232
{
206233
if (!IsLoggedIn) return Observable.Return(Unit.Default);
@@ -260,11 +287,6 @@ IObservable<AuthenticationResult> LoginWithApiUser(UserAndScopes userAndScopes)
260287
SupportsGist = userAndScopes.Scopes?.Contains("gist") ?? true;
261288
IsLoggedIn = true;
262289
}
263-
264-
log.Info("Log in from cache for login '{0}' to host '{1}' {2}",
265-
userAndScopes?.User?.Login ?? "(null)",
266-
hostAddress.ApiUri,
267-
result.IsSuccess() ? "SUCCEEDED" : "FAILED");
268290
});
269291
}
270292

0 commit comments

Comments
 (0)