@@ -24,6 +24,7 @@ import type { JSX } from 'react';
2424import { useNavigateWithTransition } from '../hooks/useNavigateWithTransition' ;
2525import { useNavState } from '../components/NavState' ;
2626import { toast } from 'react-hot-toast' ;
27+ import { errorHandler } from '../handlers/errorHandler' ;
2728
2829/** A View that opens an invite */
2930function InvitePage ( { resource } : ResourcePageProps ) : JSX . Element {
@@ -40,11 +41,15 @@ function InvitePage({ resource }: ResourcePageProps): JSX.Element {
4041 // When this happens, a new keypair is made, but the subject of the Agent is not yet known.
4142 // It will be created by the server, and will be accessible in the Redirect response.
4243 async function handleNew ( ) {
43- const keypair = await generateKeyPair ( ) ;
44- const newAgent = new Agent ( keypair . privateKey ) ;
44+ try {
45+ const keypair = await generateKeyPair ( ) ;
46+ const newAgent = new Agent ( keypair . privateKey ) ;
4547
46- setAgent ( newAgent ) ;
47- handleAccept ( keypair ) ;
48+ setAgent ( newAgent ) ;
49+ handleAccept ( keypair ) ;
50+ } catch ( error ) {
51+ store . notifyError ( error ) ;
52+ }
4853 }
4954
5055 const handleAccept = async ( keys ?: {
@@ -61,7 +66,17 @@ function InvitePage({ resource }: ResourcePageProps): JSX.Element {
6166
6267 const redirect = await store . getResource < Server . Redirect > ( inviteURL . href ) ;
6368
64- if ( redirect . props . redirectAgent && keys ) {
69+ if ( keys ) {
70+ if ( redirect . error ) {
71+ store . notifyError ( redirect . error ) ;
72+
73+ return ;
74+ }
75+
76+ if ( ! redirect . props . redirectAgent ) {
77+ throw new Error ( 'Redirect agent not found' ) ;
78+ }
79+
6580 const newAgent = new Agent ( keys . privateKey , redirect . props . redirectAgent ) ;
6681 setAgent ( newAgent ) ;
6782
0 commit comments