fix(curated_communities): fix error handling in curated communities call

This commit is contained in:
Jonathan Rainville 2023-02-28 15:14:50 -05:00
parent 1856c9de93
commit f10299ba6f
3 changed files with 17 additions and 4 deletions

View File

@ -40,6 +40,7 @@ type
view: View
viewVariant: QVariant
moduleLoaded: bool
curatedCommunitiesLoaded: bool
mintingModule: minting_module.AccessInterface
# Forward declaration
@ -66,6 +67,7 @@ proc newModule*(
)
result.mintingModule = minting_module.newMintingModule(result, events, communityTokensService)
result.moduleLoaded = false
result.curatedCommunitiesLoaded = false
method delete*(self: Module) =
self.view.delete
@ -92,9 +94,12 @@ method viewDidLoad*(self: Module) =
self.delegate.communitiesModuleDidLoad()
method onActivated*(self: Module) =
if self.curatedCommunitiesLoaded:
return
self.controller.asyncLoadCuratedCommunities()
method curatedCommunitiesLoaded*(self: Module, curatedCommunities: seq[CuratedCOmmunity]) =
self.curatedCommunitiesLoaded = true
self.setCuratedCommunities(curatedCommunities)
self.view.setCuratedCommunitiesLoading(false)
@ -102,6 +107,8 @@ method curatedCommunitiesLoading*(self: Module) =
self.view.setCuratedCommunitiesLoading(true)
method curatedCommunitiesLoadingFailed*(self: Module) =
# TODO we probably want to show an error in the UI later
self.curatedCommunitiesLoaded = true
self.view.setCuratedCommunitiesLoading(false)
proc createMemberItem(self: Module, memberId, requestId: string): MemberItem =

View File

@ -17,6 +17,11 @@ type
const asyncLoadCuratedCommunitiesTask: Task = proc(argEncoded: string) {.gcsafe, nimcall.} =
let arg = decode[AsyncLoadCuratedCommunitiesTaskArg](argEncoded)
let response = status_go.getCuratedCommunities()
arg.finish(response)
try:
let response = status_go.getCuratedCommunities()
arg.finish(response)
except Exception as e:
arg.finish(%* {
"error": RpcError(message: e.msg),
})

View File

@ -1282,6 +1282,7 @@ QtObject:
if (rpcResponseObj{"error"}.kind != JNull):
let error = Json.decode($rpcResponseObj["error"], RpcError)
error "Error requesting community info", msg = error.message
self.events.emit(SIGNAL_CURATED_COMMUNITIES_LOADING_FAILED, Args())
return
let curatedCommunities = parseCuratedCommunities(rpcResponseObj{"result"})
@ -1290,8 +1291,8 @@ QtObject:
self.events.emit(SIGNAL_CURATED_COMMUNITIES_LOADED, CuratedCommunitiesArgs(curatedCommunities: self.getCuratedCommunities()))
except Exception as e:
let errMsg = e.msg
error "error: ", errMsg
self.events.emit(SIGNAL_CURATEDCOMMUNITIES_LOADING_FAILED, Args())
error "error loading curated communities: ", errMsg
self.events.emit(SIGNAL_CURATED_COMMUNITIES_LOADING_FAILED, Args())
proc requestCommunityInfo*(self: Service, communityId: string, importing = false) =