client/api: fix reporting errors for bad logins

This commit is contained in:
rr- 2016-09-24 08:49:07 +02:00
parent d1cad99e87
commit 01fadd8f8c
1 changed files with 13 additions and 5 deletions

View File

@ -80,16 +80,24 @@ class Api extends events.EventTarget {
req.attach(key, files[key] || new Blob()); req.attach(key, files[key] || new Blob());
} }
} }
try {
if (this.userName && this.userPassword) { if (this.userName && this.userPassword) {
req.auth(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();
}); });
}); });