From 9cf84fb93f47c2c5dd283b94a9abbf7c0227b47a Mon Sep 17 00:00:00 2001 From: Ben Schumacher Date: Mon, 13 Nov 2023 09:13:54 +0100 Subject: [PATCH] [MM-55412] Use go-style error handling in team_controller (#25402) --- .../team_controller/team_controller.tsx | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/webapp/channels/src/components/team_controller/team_controller.tsx b/webapp/channels/src/components/team_controller/team_controller.tsx index 4cfc0a0601..1a986a6126 100644 --- a/webapp/channels/src/components/team_controller/team_controller.tsx +++ b/webapp/channels/src/components/team_controller/team_controller.tsx @@ -150,26 +150,26 @@ function TeamController(props: Props) { }, []); async function initTeamOrRedirect(team: Team) { - try { - await props.initializeTeam(team); - setTeam(team); - } catch (error) { + const {data: joinedTeam, error} = await props.initializeTeam(team) as ActionResult; // Fix in MM-46907; + if (error) { history.push('/error?type=team_not_found'); + return; + } + if (joinedTeam) { + setTeam(joinedTeam); } } async function joinTeamOrRedirect(teamNameParam: string, joinedOnFirstLoad: boolean) { setTeam(null); - try { - const {data: joinedTeam} = await props.joinTeam(teamNameParam, joinedOnFirstLoad) as ActionResult; // Fix in MM-46907; - if (joinedTeam) { - setTeam(joinedTeam); - } else { - throw new Error('Unable to join team'); - } - } catch (error) { + const {data: joinedTeam, error} = await props.joinTeam(teamNameParam, joinedOnFirstLoad) as ActionResult; // Fix in MM-46907; + if (error) { history.push('/error?type=team_not_found'); + return; + } + if (joinedTeam) { + setTeam(joinedTeam); } }