Skip to content

Commit 67d178a

Browse files
committed
Auto merge of #1689 - sgrif:sg-display-login-errors, r=jtgeibel
Display errors during login The code was serializing an entire response object, which didn't actually contain the errors that came back from the API, so we'd never show anything other than "Failed to log in". With this change we now show the error returned by the API if it returned any. Notably, if a user tries to create a new account while we're in read only mode, they will now see an error saying that.
2 parents 91e03d3 + e8f7bde commit 67d178a

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

app/routes/github-authorize.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import Route from '@ember/routing/route';
2-
import ajax from 'ember-fetch/ajax';
2+
import fetch from 'fetch';
33
import { serializeQueryParams } from 'ember-fetch/mixins/adapter-fetch';
44

55
/**
@@ -19,8 +19,9 @@ export default Route.extend({
1919
async beforeModel(transition) {
2020
try {
2121
let queryParams = serializeQueryParams(transition.queryParams);
22-
let d = await ajax(`/authorize?${queryParams}`);
23-
let item = JSON.stringify({ ok: true, data: d });
22+
let resp = await fetch(`/authorize?${queryParams}`);
23+
let json = await resp.json();
24+
let item = JSON.stringify({ ok: resp.ok, data: json });
2425
if (window.opener) {
2526
window.opener.github_response = item;
2627
}

app/routes/login.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ export default Route.extend({
5353
if (!response) {
5454
return;
5555
}
56-
if (!response.ok) {
57-
this.flashMessages.show('Failed to log in');
58-
return;
59-
}
56+
6057
let { data } = response;
61-
if (data.errors) {
58+
if (data && data.errors) {
6259
let error = `Failed to log in: ${data.errors[0].detail}`;
6360
this.flashMessages.show(error);
6461
return;
62+
} else if (!response.ok) {
63+
this.flashMessages.show('Failed to log in');
64+
return;
6565
}
6666

6767
let user = this.store.push(this.store.normalize('user', data.user));

0 commit comments

Comments
 (0)