* Avoid surfacing errors to the user when it's not critical * Remove now-unused GetAssertionsView * Apply cleanError() consistently * Give a better error message for Upstream Failures (http status 502) * Hide errors in notifications because they're not useful
This commit is contained in:
@@ -378,7 +378,7 @@ export class FeedModel {
|
||||
this.isLoading = false
|
||||
this.isRefreshing = false
|
||||
this.hasLoaded = true
|
||||
this.error = err ? cleanError(err.toString()) : ''
|
||||
this.error = cleanError(err)
|
||||
if (err) {
|
||||
this.rootStore.log.error('Posts feed request failed', err)
|
||||
}
|
||||
@@ -420,7 +420,11 @@ export class FeedModel {
|
||||
await this._prependAll(res)
|
||||
this._xIdle()
|
||||
} catch (e: any) {
|
||||
this._xIdle(e)
|
||||
this._xIdle() // don't bubble the error to the user
|
||||
this.rootStore.log.error('FeedView: Failed to load latest', {
|
||||
params: this.params,
|
||||
e,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -437,7 +441,11 @@ export class FeedModel {
|
||||
await this._appendAll(res)
|
||||
this._xIdle()
|
||||
} catch (e: any) {
|
||||
this._xIdle(e)
|
||||
this._xIdle() // don't bubble the error to the user
|
||||
this.rootStore.log.error('FeedView: Failed to load more', {
|
||||
params: this.params,
|
||||
e,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -463,7 +471,11 @@ export class FeedModel {
|
||||
} while (cursor && numToFetch > 0)
|
||||
this._xIdle()
|
||||
} catch (e: any) {
|
||||
this._xIdle(e)
|
||||
this._xIdle() // don't bubble the error to the user
|
||||
this.rootStore.log.error('FeedView: Failed to update', {
|
||||
params: this.params,
|
||||
e,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,123 +0,0 @@
|
||||
import {makeAutoObservable} from 'mobx'
|
||||
import {AppBskyGraphGetAssertions as GetAssertions} from '@atproto/api'
|
||||
import {RootStoreModel} from './root-store'
|
||||
|
||||
export type Assertion = GetAssertions.Assertion & {
|
||||
_reactKey: string
|
||||
}
|
||||
|
||||
export class GetAssertionsView {
|
||||
// state
|
||||
isLoading = false
|
||||
isRefreshing = false
|
||||
hasLoaded = false
|
||||
error = ''
|
||||
params: GetAssertions.QueryParams
|
||||
|
||||
// data
|
||||
assertions: Assertion[] = []
|
||||
|
||||
constructor(
|
||||
public rootStore: RootStoreModel,
|
||||
params: GetAssertions.QueryParams,
|
||||
) {
|
||||
makeAutoObservable(
|
||||
this,
|
||||
{
|
||||
rootStore: false,
|
||||
params: false,
|
||||
},
|
||||
{autoBind: true},
|
||||
)
|
||||
this.params = params
|
||||
}
|
||||
|
||||
get hasContent() {
|
||||
return this.assertions.length > 0
|
||||
}
|
||||
|
||||
get hasError() {
|
||||
return this.error !== ''
|
||||
}
|
||||
|
||||
get isEmpty() {
|
||||
return this.hasLoaded && !this.hasContent
|
||||
}
|
||||
|
||||
getBySubject(did: string) {
|
||||
return this.assertions.find(assertion => assertion.subject.did === did)
|
||||
}
|
||||
|
||||
get confirmed() {
|
||||
return this.assertions.filter(assertion => !!assertion.confirmation)
|
||||
}
|
||||
|
||||
get unconfirmed() {
|
||||
return this.assertions.filter(assertion => !assertion.confirmation)
|
||||
}
|
||||
|
||||
// public api
|
||||
// =
|
||||
|
||||
async setup() {
|
||||
await this._fetch()
|
||||
}
|
||||
|
||||
async refresh() {
|
||||
await this._fetch(true)
|
||||
}
|
||||
|
||||
async loadMore() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
// state transitions
|
||||
// =
|
||||
|
||||
private _xLoading(isRefreshing = false) {
|
||||
this.isLoading = true
|
||||
this.isRefreshing = isRefreshing
|
||||
this.error = ''
|
||||
}
|
||||
|
||||
private _xIdle(err?: any) {
|
||||
this.isLoading = false
|
||||
this.isRefreshing = false
|
||||
this.hasLoaded = true
|
||||
this.error = err ? err.toString() : ''
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch assertions', err)
|
||||
}
|
||||
}
|
||||
|
||||
// loader functions
|
||||
// =
|
||||
|
||||
private async _fetch(isRefreshing = false) {
|
||||
this._xLoading(isRefreshing)
|
||||
try {
|
||||
const res = await this.rootStore.api.app.bsky.graph.getAssertions(
|
||||
this.params,
|
||||
)
|
||||
this._replaceAll(res)
|
||||
this._xIdle()
|
||||
} catch (e: any) {
|
||||
this._xIdle(e)
|
||||
}
|
||||
}
|
||||
|
||||
private _replaceAll(res: GetAssertions.Response) {
|
||||
this.assertions.length = 0
|
||||
let counter = 0
|
||||
for (const item of res.data.assertions) {
|
||||
this._append({
|
||||
_reactKey: `item-${counter++}`,
|
||||
...item,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private _append(item: Assertion) {
|
||||
this.assertions.push(item)
|
||||
}
|
||||
}
|
||||
@@ -329,7 +329,6 @@ export class NotificationsViewModel {
|
||||
this.isRefreshing = false
|
||||
this.hasLoaded = true
|
||||
this.error = cleanError(err)
|
||||
this.error = err ? cleanError(err) : ''
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch notifications', err)
|
||||
}
|
||||
@@ -378,7 +377,11 @@ export class NotificationsViewModel {
|
||||
await this._appendAll(res)
|
||||
this._xIdle()
|
||||
} catch (e: any) {
|
||||
this._xIdle(e)
|
||||
this._xIdle() // don't bubble the error to the user
|
||||
this.rootStore.log.error('NotificationsView: Failed to load more', {
|
||||
params: this.params,
|
||||
e,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -405,7 +408,11 @@ export class NotificationsViewModel {
|
||||
} while (cursor && numToFetch > 0)
|
||||
this._xIdle()
|
||||
} catch (e: any) {
|
||||
this._xIdle(e)
|
||||
this._xIdle() // don't bubble the error to the user
|
||||
this.rootStore.log.error('NotificationsView: Failed to update', {
|
||||
params: this.params,
|
||||
e,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
import {AtUri} from '../../third-party/uri'
|
||||
import {RootStoreModel} from './root-store'
|
||||
import * as apilib from '../lib/api'
|
||||
import {cleanError} from '../../lib/strings'
|
||||
|
||||
function* reactKeyGenerator(): Generator<string> {
|
||||
let counter = 0
|
||||
@@ -276,7 +277,7 @@ export class PostThreadViewModel {
|
||||
this.isLoading = false
|
||||
this.isRefreshing = false
|
||||
this.hasLoaded = true
|
||||
this.error = err ? err.toString() : ''
|
||||
this.error = cleanError(err)
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch post thread', err)
|
||||
}
|
||||
|
||||
@@ -67,7 +67,6 @@ export class PostModel implements RemoveIndex<Post.Record> {
|
||||
this.isLoading = false
|
||||
this.hasLoaded = true
|
||||
this.error = cleanError(err)
|
||||
this.error = err ? cleanError(err) : ''
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch post', err)
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ type Entity = AppBskyFeedPost.Entity
|
||||
import {extractEntities} from '../../lib/strings'
|
||||
import {RootStoreModel} from './root-store'
|
||||
import * as apilib from '../lib/api'
|
||||
import {cleanError} from '../../lib/strings'
|
||||
|
||||
export const ACTOR_TYPE_USER = 'app.bsky.system.actorUser'
|
||||
|
||||
@@ -175,7 +176,7 @@ export class ProfileViewModel {
|
||||
this.isLoading = false
|
||||
this.isRefreshing = false
|
||||
this.hasLoaded = true
|
||||
this.error = err ? err.toString() : ''
|
||||
this.error = cleanError(err)
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch profile', err)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import {makeAutoObservable, runInAction} from 'mobx'
|
||||
import {AtUri} from '../../third-party/uri'
|
||||
import {AppBskyFeedGetRepostedBy as GetRepostedBy} from '@atproto/api'
|
||||
import {RootStoreModel} from './root-store'
|
||||
import {cleanError} from '../../lib/strings'
|
||||
|
||||
const PAGE_SIZE = 30
|
||||
|
||||
@@ -82,7 +83,7 @@ export class RepostedByViewModel {
|
||||
this.isLoading = false
|
||||
this.isRefreshing = false
|
||||
this.hasLoaded = true
|
||||
this.error = err ? err.toString() : ''
|
||||
this.error = cleanError(err)
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch reposted by view', err)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {makeAutoObservable, runInAction} from 'mobx'
|
||||
import {AppBskyActorGetSuggestions as GetSuggestions} from '@atproto/api'
|
||||
import {RootStoreModel} from './root-store'
|
||||
import {cleanError} from '../../lib/strings'
|
||||
|
||||
const PAGE_SIZE = 30
|
||||
|
||||
@@ -70,7 +71,7 @@ export class SuggestedActorsViewModel {
|
||||
this.isLoading = false
|
||||
this.isRefreshing = false
|
||||
this.hasLoaded = true
|
||||
this.error = err ? err.toString() : ''
|
||||
this.error = cleanError(err)
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch suggested actors', err)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
AppBskyActorRef as ActorRef,
|
||||
} from '@atproto/api'
|
||||
import {RootStoreModel} from './root-store'
|
||||
import {cleanError} from '../../lib/strings'
|
||||
|
||||
const PAGE_SIZE = 30
|
||||
|
||||
@@ -84,7 +85,7 @@ export class UserFollowersViewModel {
|
||||
this.isLoading = false
|
||||
this.isRefreshing = false
|
||||
this.hasLoaded = true
|
||||
this.error = err ? err.toString() : ''
|
||||
this.error = cleanError(err)
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch user followers', err)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
AppBskyActorRef as ActorRef,
|
||||
} from '@atproto/api'
|
||||
import {RootStoreModel} from './root-store'
|
||||
import {cleanError} from '../../lib/strings'
|
||||
|
||||
const PAGE_SIZE = 30
|
||||
|
||||
@@ -84,7 +85,7 @@ export class UserFollowsViewModel {
|
||||
this.isLoading = false
|
||||
this.isRefreshing = false
|
||||
this.hasLoaded = true
|
||||
this.error = err ? err.toString() : ''
|
||||
this.error = cleanError(err)
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch user follows', err)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import {makeAutoObservable, runInAction} from 'mobx'
|
||||
import {AtUri} from '../../third-party/uri'
|
||||
import {AppBskyFeedGetVotes as GetVotes} from '@atproto/api'
|
||||
import {RootStoreModel} from './root-store'
|
||||
import {cleanError} from '../../lib/strings'
|
||||
|
||||
const PAGE_SIZE = 30
|
||||
|
||||
@@ -79,7 +80,7 @@ export class VotesViewModel {
|
||||
this.isLoading = false
|
||||
this.isRefreshing = false
|
||||
this.hasLoaded = true
|
||||
this.error = err ? err.toString() : ''
|
||||
this.error = cleanError(err)
|
||||
if (err) {
|
||||
this.rootStore.log.error('Failed to fetch votes', err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user