mirror of
https://github.com/NicolasConstant/sengi
synced 2025-01-14 01:34:17 +01:00
format better http error display
This commit is contained in:
parent
ef4c252f42
commit
4e6f71f5b2
@ -1,4 +1,5 @@
|
||||
import { Component, OnInit, OnDestroy, Input, Output, EventEmitter } from '@angular/core';
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
import { Store } from '@ngxs/store';
|
||||
import { Observable, Subscription } from 'rxjs';
|
||||
|
||||
@ -7,6 +8,7 @@ import { MastodonService } from '../../../../services/mastodon.service';
|
||||
import { AccountInfo } from '../../../../states/accounts.state';
|
||||
import { Status, Results } from '../../../../services/models/mastodon.interfaces';
|
||||
import { ToolsService } from '../../../../services/tools.service';
|
||||
import { NotificationService } from '../../../../services/notification.service';
|
||||
// import { map } from "rxjs/operators";
|
||||
|
||||
@Component({
|
||||
@ -37,15 +39,13 @@ export class ActionBarComponent implements OnInit, OnDestroy {
|
||||
constructor(
|
||||
private readonly store: Store,
|
||||
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);
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
// const selectedAccounts = this.getSelectedAccounts();
|
||||
// this.checkStatus(selectedAccounts);
|
||||
|
||||
const status = this.statusWrapper.status;
|
||||
const account = this.statusWrapper.provider;
|
||||
this.favoriteStatePerAccountId[account.id] = status.favourited;
|
||||
@ -88,25 +88,10 @@ export class ActionBarComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
boost(): boolean {
|
||||
|
||||
//TODO get rid of that
|
||||
this.selectedAccounts.forEach((account: AccountInfo) => {
|
||||
|
||||
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
|
||||
.then((status: Status) => {
|
||||
if (this.isBoosted) {
|
||||
@ -120,8 +105,8 @@ export class ActionBarComponent implements OnInit, OnDestroy {
|
||||
this.checkIfBoosted();
|
||||
// this.isBoosted = !this.isBoosted;
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
.catch((err: HttpErrorResponse) => {
|
||||
this.notificationService.notifyHttpError(err);
|
||||
});
|
||||
});
|
||||
|
||||
@ -132,20 +117,6 @@ export class ActionBarComponent implements OnInit, OnDestroy {
|
||||
this.selectedAccounts.forEach((account: AccountInfo) => {
|
||||
|
||||
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
|
||||
.then((status: Status) => {
|
||||
if (this.isFavorited) {
|
||||
@ -159,8 +130,8 @@ export class ActionBarComponent implements OnInit, OnDestroy {
|
||||
this.checkIfFavorited();
|
||||
// this.isFavorited = !this.isFavorited;
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
.catch((err: HttpErrorResponse) => {
|
||||
this.notificationService.notifyHttpError(err);
|
||||
});
|
||||
});
|
||||
return false;
|
||||
|
@ -15,7 +15,8 @@ export class NotificationService {
|
||||
}
|
||||
|
||||
public notifyHttpError(err: HttpErrorResponse){
|
||||
let message = `${err.status}: ${err.message}`;
|
||||
console.error(err.message);
|
||||
let message = `${err.status}: ${err.statusText}`;
|
||||
this.notify(message, true);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user