added error handling in all http calls
This commit is contained in:
parent
4e6f71f5b2
commit
a2216a6df6
@ -1,8 +1,11 @@
|
||||
import { Component, OnInit, Input } from '@angular/core';
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
import { Store } from '@ngxs/store';
|
||||
|
||||
import { RegisteredAppsStateModel, AppInfo, AddRegisteredApp } from '../../../states/registered-apps.state';
|
||||
import { AuthService, CurrentAuthProcess } from '../../../services/auth.service';
|
||||
import { Store } from '@ngxs/store';
|
||||
import { AppData } from '../../../services/models/mastodon.interfaces';
|
||||
import { NotificationService } from '../../../services/notification.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-add-new-account',
|
||||
@ -13,6 +16,7 @@ export class AddNewAccountComponent implements OnInit {
|
||||
@Input() mastodonFullHandle: string;
|
||||
|
||||
constructor(
|
||||
private readonly notificationService: NotificationService,
|
||||
private readonly authService: AuthService,
|
||||
private readonly store: Store) { }
|
||||
|
||||
@ -28,6 +32,9 @@ export class AddNewAccountComponent implements OnInit {
|
||||
this.checkAndCreateApplication(instance)
|
||||
.then((appData: AppData) => {
|
||||
this.redirectToInstanceAuthPage(username, instance, appData);
|
||||
})
|
||||
.catch((err: HttpErrorResponse) => {
|
||||
this.notificationService.notifyHttpError(err);
|
||||
});
|
||||
|
||||
return false;
|
||||
@ -38,10 +45,8 @@ export class AddNewAccountComponent implements OnInit {
|
||||
const instanceApps = alreadyRegisteredApps.filter(x => x.instance === instance);
|
||||
|
||||
if (instanceApps.length !== 0) {
|
||||
console.log('instance already registered');
|
||||
return Promise.resolve(instanceApps[0].app);
|
||||
} else {
|
||||
console.log('instance not registered');
|
||||
const redirect_uri = this.getLocalHostname() + '/register';
|
||||
return this.authService.createNewApplication(instance, 'Sengi', redirect_uri, 'read write follow', 'https://github.com/NicolasConstant/sengi')
|
||||
.then((appData: AppData) => {
|
||||
|
@ -1,9 +1,11 @@
|
||||
import { Component, OnInit, Input, ElementRef, ViewChild } from '@angular/core';
|
||||
import { Store } from '@ngxs/store';
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
|
||||
import { AccountInfo } from '../../../states/accounts.state';
|
||||
import { MastodonService, VisibilityEnum } from '../../../services/mastodon.service';
|
||||
import { Status } from '../../../services/models/mastodon.interfaces';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import { NotificationService } from '../../../services/notification.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-add-new-status',
|
||||
@ -20,6 +22,7 @@ export class AddNewStatusComponent implements OnInit {
|
||||
|
||||
constructor(
|
||||
private readonly store: Store,
|
||||
private readonly notificationService: NotificationService,
|
||||
private readonly mastodonService: MastodonService) { }
|
||||
|
||||
ngOnInit() {
|
||||
@ -56,9 +59,11 @@ export class AddNewStatusComponent implements OnInit {
|
||||
for (const acc of selectedAccounts) {
|
||||
this.mastodonService.postNewStatus(acc, this.status, visibility, spoiler)
|
||||
.then((res: Status) => {
|
||||
console.log(res);
|
||||
this.title = '';
|
||||
this.status = '';
|
||||
})
|
||||
.catch((err: HttpErrorResponse) => {
|
||||
this.notificationService.notifyHttpError(err);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -31,9 +31,10 @@ export class ManageAccountComponent implements OnInit {
|
||||
|
||||
addStream(stream: StreamElement): boolean {
|
||||
if (stream) {
|
||||
this.store.dispatch([new AddStream(stream)]).toPromise().then(() => {
|
||||
this.notificationService.notify(`added ${stream.displayableFullName}`, false);
|
||||
});
|
||||
this.store.dispatch([new AddStream(stream)]).toPromise()
|
||||
.then(() => {
|
||||
this.notificationService.notify(`${stream.displayableFullName} added`, false);
|
||||
});
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -1,13 +1,12 @@
|
||||
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
|
||||
import { Store } from '@ngxs/store';
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
|
||||
import { MastodonService } from '../../../services/mastodon.service';
|
||||
import { AccountInfo } from '../../../states/accounts.state';
|
||||
import { Results, Account, Status } from '../../../services/models/mastodon.interfaces';
|
||||
import { Results, Account } from '../../../services/models/mastodon.interfaces';
|
||||
import { ToolsService } from '../../../services/tools.service';
|
||||
import { StatusWrapper } from '../../stream/stream.component';
|
||||
import { StreamElement, StreamTypeEnum, AddStream } from './../../../states/streams.state';
|
||||
|
||||
import { NotificationService } from '../../../services/notification.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-search',
|
||||
@ -28,6 +27,7 @@ export class SearchComponent implements OnInit {
|
||||
@Output() browseThreadEvent = new EventEmitter<string>();
|
||||
|
||||
constructor(
|
||||
private readonly notificationService: NotificationService,
|
||||
private readonly toolsService: ToolsService,
|
||||
private readonly mastodonService: MastodonService) { }
|
||||
|
||||
@ -84,11 +84,11 @@ export class SearchComponent implements OnInit {
|
||||
const statusWrapper = new StatusWrapper(status, this.lastAccountUsed);
|
||||
this.statuses.push(statusWrapper);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
})
|
||||
.catch((err) => console.error(err))
|
||||
.catch((err: HttpErrorResponse) => {
|
||||
this.notificationService.notifyHttpError(err);
|
||||
})
|
||||
.then(() => { this.isLoading = false; });
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { Component, OnInit, OnDestroy } from "@angular/core";
|
||||
import { HttpErrorResponse } from "@angular/common/http";
|
||||
import { Subscription, Observable } from "rxjs";
|
||||
import { Store } from "@ngxs/store";
|
||||
import { faCommentAlt } from "@fortawesome/free-regular-svg-icons";
|
||||
@ -8,7 +9,7 @@ import { AccountWrapper } from "../../models/account.models";
|
||||
import { AccountInfo, SelectAccount } from "../../states/accounts.state";
|
||||
import { NavigationService, LeftPanelType } from "../../services/navigation.service";
|
||||
import { MastodonService } from "../../services/mastodon.service";
|
||||
|
||||
import { NotificationService } from "../../services/notification.service";
|
||||
|
||||
@Component({
|
||||
selector: "app-left-side-bar",
|
||||
@ -26,6 +27,7 @@ export class LeftSideBarComponent implements OnInit, OnDestroy {
|
||||
private sub: Subscription;
|
||||
|
||||
constructor(
|
||||
private readonly notificationService: NotificationService,
|
||||
private readonly navigationService: NavigationService,
|
||||
private readonly mastodonService: MastodonService,
|
||||
private readonly store: Store) {
|
||||
@ -50,6 +52,9 @@ export class LeftSideBarComponent implements OnInit, OnDestroy {
|
||||
this.mastodonService.retrieveAccountDetails(acc)
|
||||
.then((result: Account) => {
|
||||
accWrapper.avatar = result.avatar;
|
||||
})
|
||||
.catch((err: HttpErrorResponse) => {
|
||||
this.notificationService.notifyHttpError(err);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +75,6 @@ export class ReplyToStatusComponent implements OnInit {
|
||||
return this.mastodonService.postNewStatus(acc, this.status, visibility, spoiler, status.id);
|
||||
})
|
||||
.then((res: Status) => {
|
||||
console.log(res);
|
||||
this.status = '';
|
||||
this.onClose.emit();
|
||||
})
|
||||
|
@ -52,8 +52,6 @@ export class StreamOverlayComponent implements OnInit {
|
||||
}
|
||||
|
||||
next(): boolean {
|
||||
console.log('next');
|
||||
|
||||
if (this.nextElements.length === 0) {
|
||||
return false;
|
||||
}
|
||||
@ -70,8 +68,6 @@ export class StreamOverlayComponent implements OnInit {
|
||||
}
|
||||
|
||||
previous(): boolean {
|
||||
console.log('previous');
|
||||
|
||||
if (this.previousElements.length === 0) {
|
||||
this.closeOverlay.next();
|
||||
return false;
|
||||
@ -96,7 +92,6 @@ export class StreamOverlayComponent implements OnInit {
|
||||
browseAccount(accountName: string): void {
|
||||
if(!accountName) return;
|
||||
|
||||
console.log('accountSelected');
|
||||
this.nextElements.length = 0;
|
||||
if (this.currentElement) {
|
||||
this.previousElements.push(this.currentElement);
|
||||
@ -109,7 +104,6 @@ export class StreamOverlayComponent implements OnInit {
|
||||
browseHashtag(hashtag: string): void {
|
||||
if(!hashtag) return;
|
||||
|
||||
console.log('hashtagSelected');
|
||||
this.nextElements.length = 0;
|
||||
if (this.currentElement) {
|
||||
this.previousElements.push(this.currentElement);
|
||||
@ -125,7 +119,6 @@ export class StreamOverlayComponent implements OnInit {
|
||||
browseThread(statusUri: string): any {
|
||||
if(!statusUri) return;
|
||||
|
||||
console.log('thread selected')
|
||||
this.nextElements.length = 0;
|
||||
if (this.currentElement) {
|
||||
this.previousElements.push(this.currentElement);
|
||||
|
@ -1,4 +1,6 @@
|
||||
import { Component, OnInit, Input, ViewChild, ElementRef, OnDestroy, EventEmitter, Output } from '@angular/core';
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
import { Observable, Subscription } from 'rxjs';
|
||||
import { Store } from '@ngxs/store';
|
||||
|
||||
import { StreamElement } from '../../../states/streams.state';
|
||||
@ -6,9 +8,8 @@ import { AccountInfo } from '../../../states/accounts.state';
|
||||
import { StreamingService, EventEnum, StreamingWrapper, StatusUpdate } from '../../../services/streaming.service';
|
||||
import { Status } from '../../../services/models/mastodon.interfaces';
|
||||
import { MastodonService } from '../../../services/mastodon.service';
|
||||
import { Observable, Subscription } from 'rxjs';
|
||||
import { StatusWrapper } from '../stream.component';
|
||||
|
||||
import { NotificationService } from '../../../services/notification.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-stream-statuses',
|
||||
@ -54,6 +55,7 @@ export class StreamStatusesComponent implements OnInit, OnDestroy {
|
||||
|
||||
constructor(
|
||||
private readonly store: Store,
|
||||
private readonly notificationService: NotificationService,
|
||||
private readonly streamingService: StreamingService,
|
||||
private readonly mastodonService: MastodonService) {
|
||||
}
|
||||
@ -172,8 +174,8 @@ export class StreamStatusesComponent implements OnInit, OnDestroy {
|
||||
this.statuses.push(wrapper);
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
.catch((err: HttpErrorResponse) => {
|
||||
this.notificationService.notifyHttpError(err);
|
||||
})
|
||||
.then(() => {
|
||||
this.isProcessingInfiniteScroll = false;
|
||||
@ -193,6 +195,9 @@ export class StreamStatusesComponent implements OnInit, OnDestroy {
|
||||
const wrapper = new StatusWrapper(s, this.account);
|
||||
this.statuses.push(wrapper);
|
||||
}
|
||||
})
|
||||
.catch((err: HttpErrorResponse) => {
|
||||
this.notificationService.notifyHttpError(err);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,6 @@ export class StreamComponent implements OnInit {
|
||||
|
||||
editionPanelIsOpen: boolean;
|
||||
openEditionMenu(): boolean {
|
||||
console.log('opened menu');
|
||||
this.editionPanelIsOpen = !this.editionPanelIsOpen;
|
||||
return false;
|
||||
}
|
||||
|
@ -1,8 +1,11 @@
|
||||
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
|
||||
import { StatusWrapper } from '../stream.component';
|
||||
import { MastodonService } from '../../../services/mastodon.service';
|
||||
import { ToolsService } from '../../../services/tools.service';
|
||||
import { Status, Results, Context } from '../../../services/models/mastodon.interfaces';
|
||||
import { Results, Context } from '../../../services/models/mastodon.interfaces';
|
||||
import { NotificationService } from '../../../services/notification.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-thread',
|
||||
@ -26,6 +29,7 @@ export class ThreadComponent implements OnInit {
|
||||
}
|
||||
|
||||
constructor(
|
||||
private readonly notificationService: NotificationService,
|
||||
private readonly toolsService: ToolsService,
|
||||
private readonly mastodonService: MastodonService) { }
|
||||
|
||||
@ -56,6 +60,9 @@ export class ThreadComponent implements OnInit {
|
||||
this.isLoading = false;
|
||||
console.error('could not retrieve status');
|
||||
}
|
||||
})
|
||||
.catch((err: HttpErrorResponse) => {
|
||||
this.notificationService.notifyHttpError(err);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,11 @@
|
||||
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
|
||||
import { Account, Status, Results } from "../../../services/models/mastodon.interfaces";
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
|
||||
import { Account, Status} from "../../../services/models/mastodon.interfaces";
|
||||
import { MastodonService } from '../../../services/mastodon.service';
|
||||
import { ToolsService } from '../../../services/tools.service';
|
||||
import { StatusWrapper } from '../stream.component';
|
||||
import { NotificationService } from '../../../services/notification.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-user-profile',
|
||||
@ -37,15 +40,17 @@ export class UserProfileComponent implements OnInit {
|
||||
this.hasNote = account && account.note && account.note !== '<p></p>';
|
||||
return this.getStatuses(this.account);
|
||||
})
|
||||
.catch(err => {
|
||||
this.error = 'Error when retrieving account';
|
||||
.catch((err: HttpErrorResponse) => {
|
||||
this.notificationService.notifyHttpError(err);
|
||||
})
|
||||
.then(() => {
|
||||
this.isLoading = false;
|
||||
this.statusLoading = false;
|
||||
console.error(this.error);
|
||||
});
|
||||
}
|
||||
|
||||
constructor(
|
||||
private readonly notificationService: NotificationService,
|
||||
private readonly mastodonService: MastodonService,
|
||||
private readonly toolsService: ToolsService) { }
|
||||
|
||||
@ -95,12 +100,6 @@ export class UserProfileComponent implements OnInit {
|
||||
this.statuses.push(wrapper);
|
||||
}
|
||||
this.statusLoading = false;
|
||||
});
|
||||
// .catch(err => {
|
||||
|
||||
// })
|
||||
// .then(() => {
|
||||
// this.statusLoading = false;
|
||||
// });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { Component, OnInit, Input } from "@angular/core";
|
||||
import { Store, Select } from '@ngxs/store';
|
||||
import { ActivatedRoute, Router } from "@angular/router";
|
||||
import { Observable } from "rxjs";
|
||||
import { HttpErrorResponse } from "@angular/common/http";
|
||||
|
||||
import { AuthService, CurrentAuthProcess } from "../../services/auth.service";
|
||||
import { TokenData, AppData } from "../../services/models/mastodon.interfaces";
|
||||
import { AddRegisteredApp, RegisteredAppsState, RegisteredAppsStateModel, AppInfo } from "../../states/registered-apps.state";
|
||||
import { TokenData } from "../../services/models/mastodon.interfaces";
|
||||
import { RegisteredAppsStateModel, AppInfo } from "../../states/registered-apps.state";
|
||||
import { AccountInfo, AddAccount } from "../../states/accounts.state";
|
||||
import { MastodonService } from "../../services/mastodon.service";
|
||||
import { NotificationService } from "../../services/notification.service";
|
||||
|
||||
@Component({
|
||||
selector: "app-register-new-account",
|
||||
@ -23,6 +23,7 @@ export class RegisterNewAccountComponent implements OnInit {
|
||||
private authStorageKey: string = 'tempAuth';
|
||||
|
||||
constructor(
|
||||
private readonly notificationService: NotificationService,
|
||||
private readonly authService: AuthService,
|
||||
private readonly store: Store,
|
||||
private readonly activatedRoute: ActivatedRoute,
|
||||
@ -57,6 +58,9 @@ export class RegisterNewAccountComponent implements OnInit {
|
||||
localStorage.removeItem(this.authStorageKey);
|
||||
this.router.navigate(['/home']);
|
||||
});
|
||||
})
|
||||
.catch((err: HttpErrorResponse) => {
|
||||
this.notificationService.notifyHttpError(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user