format better http error display

This commit is contained in:
Nicolas Constant 2019-02-11 22:33:54 -05:00
parent ef4c252f42
commit 4e6f71f5b2
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
2 changed files with 10 additions and 38 deletions

View File

@ -1,4 +1,5 @@
import { Component, OnInit, OnDestroy, Input, Output, EventEmitter } from '@angular/core'; import { Component, OnInit, OnDestroy, Input, Output, EventEmitter } from '@angular/core';
import { HttpErrorResponse } from '@angular/common/http';
import { Store } from '@ngxs/store'; import { Store } from '@ngxs/store';
import { Observable, Subscription } from 'rxjs'; import { Observable, Subscription } from 'rxjs';
@ -7,6 +8,7 @@ import { MastodonService } from '../../../../services/mastodon.service';
import { AccountInfo } from '../../../../states/accounts.state'; import { AccountInfo } from '../../../../states/accounts.state';
import { Status, Results } from '../../../../services/models/mastodon.interfaces'; import { Status, Results } from '../../../../services/models/mastodon.interfaces';
import { ToolsService } from '../../../../services/tools.service'; import { ToolsService } from '../../../../services/tools.service';
import { NotificationService } from '../../../../services/notification.service';
// import { map } from "rxjs/operators"; // import { map } from "rxjs/operators";
@Component({ @Component({
@ -37,15 +39,13 @@ export class ActionBarComponent implements OnInit, OnDestroy {
constructor( constructor(
private readonly store: Store, private readonly store: Store,
private readonly toolsService: ToolsService, private readonly toolsService: ToolsService,
private readonly mastodonService: MastodonService) { private readonly mastodonService: MastodonService,
private readonly notificationService: NotificationService) {
this.accounts$ = this.store.select(state => state.registeredaccounts.accounts); this.accounts$ = this.store.select(state => state.registeredaccounts.accounts);
} }
ngOnInit() { ngOnInit() {
// const selectedAccounts = this.getSelectedAccounts();
// this.checkStatus(selectedAccounts);
const status = this.statusWrapper.status; const status = this.statusWrapper.status;
const account = this.statusWrapper.provider; const account = this.statusWrapper.provider;
this.favoriteStatePerAccountId[account.id] = status.favourited; this.favoriteStatePerAccountId[account.id] = status.favourited;
@ -88,25 +88,10 @@ export class ActionBarComponent implements OnInit, OnDestroy {
} }
boost(): boolean { boost(): boolean {
//TODO get rid of that //TODO get rid of that
this.selectedAccounts.forEach((account: AccountInfo) => { this.selectedAccounts.forEach((account: AccountInfo) => {
const usableStatus = this.toolsService.getStatusUsableByAccount(account, this.statusWrapper); const usableStatus = this.toolsService.getStatusUsableByAccount(account, this.statusWrapper);
// const isProvider = this.statusWrapper.provider.id === account.id;
// let pipeline: Promise<Status> = Promise.resolve(this.statusWrapper.status);
// if (!isProvider) {
// pipeline = pipeline.then((foreignStatus: Status) => {
// const statusUrl = foreignStatus.url;
// return this.mastodonService.search(account, statusUrl)
// .then((results: Results) => {
// //TODO check and type errors
// return results.statuses[0];
// });
// });
// }
usableStatus usableStatus
.then((status: Status) => { .then((status: Status) => {
if (this.isBoosted) { if (this.isBoosted) {
@ -120,8 +105,8 @@ export class ActionBarComponent implements OnInit, OnDestroy {
this.checkIfBoosted(); this.checkIfBoosted();
// this.isBoosted = !this.isBoosted; // this.isBoosted = !this.isBoosted;
}) })
.catch(err => { .catch((err: HttpErrorResponse) => {
console.error(err); this.notificationService.notifyHttpError(err);
}); });
}); });
@ -132,20 +117,6 @@ export class ActionBarComponent implements OnInit, OnDestroy {
this.selectedAccounts.forEach((account: AccountInfo) => { this.selectedAccounts.forEach((account: AccountInfo) => {
const usableStatus = this.toolsService.getStatusUsableByAccount(account, this.statusWrapper); const usableStatus = this.toolsService.getStatusUsableByAccount(account, this.statusWrapper);
// const isProvider = this.statusWrapper.provider.id === account.id;
// let pipeline: Promise<Status> = Promise.resolve(this.statusWrapper.status);
// if (!isProvider) {
// pipeline = pipeline.then((foreignStatus: Status) => {
// const statusUrl = foreignStatus.url;
// return this.mastodonService.search(account, statusUrl)
// .then((results: Results) => {
// //TODO check and type errors
// return results.statuses[0];
// });
// });
// }
usableStatus usableStatus
.then((status: Status) => { .then((status: Status) => {
if (this.isFavorited) { if (this.isFavorited) {
@ -159,8 +130,8 @@ export class ActionBarComponent implements OnInit, OnDestroy {
this.checkIfFavorited(); this.checkIfFavorited();
// this.isFavorited = !this.isFavorited; // this.isFavorited = !this.isFavorited;
}) })
.catch(err => { .catch((err: HttpErrorResponse) => {
console.error(err); this.notificationService.notifyHttpError(err);
}); });
}); });
return false; return false;

View File

@ -15,7 +15,8 @@ export class NotificationService {
} }
public notifyHttpError(err: HttpErrorResponse){ public notifyHttpError(err: HttpErrorResponse){
let message = `${err.status}: ${err.message}`; console.error(err.message);
let message = `${err.status}: ${err.statusText}`;
this.notify(message, true); this.notify(message, true);
} }
} }