From f10299ba6f265d034afa99d4b78a9c8ff1a9a8d2 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Tue, 28 Feb 2023 15:14:50 -0500 Subject: [PATCH] fix(curated_communities): fix error handling in curated communities call --- src/app/modules/main/communities/module.nim | 7 +++++++ src/app_service/service/community/async_tasks.nim | 9 +++++++-- src/app_service/service/community/service.nim | 5 +++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/app/modules/main/communities/module.nim b/src/app/modules/main/communities/module.nim index 6dbb62ce67..d099e7e637 100644 --- a/src/app/modules/main/communities/module.nim +++ b/src/app/modules/main/communities/module.nim @@ -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 = diff --git a/src/app_service/service/community/async_tasks.nim b/src/app_service/service/community/async_tasks.nim index 7b50ac58f0..82319b836f 100644 --- a/src/app_service/service/community/async_tasks.nim +++ b/src/app_service/service/community/async_tasks.nim @@ -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), + }) diff --git a/src/app_service/service/community/service.nim b/src/app_service/service/community/service.nim index 16de588a8c..d0e5bc5e66 100644 --- a/src/app_service/service/community/service.nim +++ b/src/app_service/service/community/service.nim @@ -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) =