client/api: fix reporting errors for bad logins
This commit is contained in:
parent
d1cad99e87
commit
01fadd8f8c
|
@ -80,16 +80,24 @@ class Api extends events.EventTarget {
|
||||||
req.attach(key, files[key] || new Blob());
|
req.attach(key, files[key] || new Blob());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.userName && this.userPassword) {
|
try {
|
||||||
req.auth(this.userName, this.userPassword);
|
if (this.userName && this.userPassword) {
|
||||||
|
req.auth(
|
||||||
|
this.userName,
|
||||||
|
this.userPassword);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
reject({
|
||||||
|
title: 'Authentication error',
|
||||||
|
description: 'Malformed credentials'});
|
||||||
}
|
}
|
||||||
req.set('Accept', 'application/json')
|
req.set('Accept', 'application/json')
|
||||||
.end((error, response) => {
|
.end((error, response) => {
|
||||||
nprogress.done();
|
nprogress.done();
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(response && response.body ? response.body : {
|
reject(response && response.body ? response.body : {
|
||||||
'title': 'Networking error',
|
title: 'Networking error',
|
||||||
'description': error.message});
|
description: error.message});
|
||||||
} else {
|
} else {
|
||||||
resolve(response.body);
|
resolve(response.body);
|
||||||
}
|
}
|
||||||
|
@ -152,7 +160,7 @@ class Api extends events.EventTarget {
|
||||||
resolve();
|
resolve();
|
||||||
this.dispatchEvent(new CustomEvent('login'));
|
this.dispatchEvent(new CustomEvent('login'));
|
||||||
}, response => {
|
}, response => {
|
||||||
reject(response.description);
|
reject(response.description || response || 'Unknown error');
|
||||||
this.logout();
|
this.logout();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue