Added an dedicated error in case of a potential CORS issue #39

This commit is contained in:
Nicolas Constant 2019-03-03 18:42:11 -05:00
parent 5a7f6bf87f
commit de42f445b4
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
3 changed files with 22 additions and 6 deletions

View File

@ -34,7 +34,13 @@ export class AddNewAccountComponent implements OnInit {
this.redirectToInstanceAuthPage(username, instance, appData);
})
.catch((err: HttpErrorResponse) => {
this.notificationService.notifyHttpError(err);
if (err instanceof HttpErrorResponse) {
this.notificationService.notifyHttpError(err);
} else if ((<Error>err).message === 'CORS'){
this.notificationService.notify('There is maybe a CORS issue with the server you\'re connecting to. Please check in the console and if so, contact your administrator with those informations.', true);
} else {
this.notificationService.notify('Unkown error', true);
}
});
return false;
@ -53,6 +59,13 @@ export class AddNewAccountComponent implements OnInit {
return this.saveNewApp(instance, appData)
.then(() => { return appData; });
})
.catch((err: HttpErrorResponse) => {
if (err.status === 0) {
throw Error('CORS');
} else {
throw err;
}
});
}
}
@ -60,7 +73,7 @@ export class AddNewAccountComponent implements OnInit {
const snapshot = <RegisteredAppsStateModel>this.store.snapshot().registeredapps;
return snapshot.apps;
}
private redirectToInstanceAuthPage(username: string, instance: string, app: AppData) {
const appDataTemp = new CurrentAuthProcess(username, instance);
localStorage.setItem('tempAuth', JSON.stringify(appDataTemp));
@ -69,11 +82,11 @@ export class AddNewAccountComponent implements OnInit {
window.location.href = instanceUrl;
}
private getLocalHostname(): string {
let localHostname = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '');
return localHostname;
}
}
private saveNewApp(instance: string, app: AppData): Promise<any> {
const appInfo = new AppInfo();

View File

@ -1,5 +1,5 @@
.notification-hub {
position: fixed;
position: fixed;
bottom: 30px;
z-index: 9999999;
margin: 0 0 10px 0;
@ -10,6 +10,9 @@
padding: 5px 10px;
border-radius: 2px;
margin: 0 0 5px 15px;
max-width: 305px;
white-space: pre-line;
word-wrap: break-word;
cursor: pointer;
&--error{

View File

@ -17,7 +17,7 @@ export class NotificationHubComponent implements OnInit {
setTimeout(() => {
this.notifications = this.notifications.filter(x => x.id !== notification.id);
}, 2000);
}, 5000);
});
//this.autoSubmit();