@@ -9,7 +9,6 @@ import { useMemo, useState } from 'react';
99import { type SubmitHandler , useForm } from 'react-hook-form' ;
1010import { useNavigate } from 'react-router-dom' ;
1111import { z } from 'zod' ;
12-
1312import { useI18nContext } from '../../../../../../../../i18n/i18n-react' ;
1413import { FormInput } from '../../../../../../../../shared/defguard-ui/components/Form/FormInput/FormInput' ;
1514import { Button } from '../../../../../../../../shared/defguard-ui/components/Layout/Button/Button' ;
@@ -24,6 +23,7 @@ import type {
2423 EnrollmentStartResponse ,
2524} from '../../../../../../../../shared/hooks/api/types' ;
2625import { routes } from '../../../../../../../../shared/routes' ;
26+ import { errorDetail } from '../../../../../../../../shared/utils/errorDetail' ;
2727import { useEnrollmentStore } from '../../../../../../../enrollment/hooks/store/useEnrollmentStore' ;
2828import { clientApi } from '../../../../../../clientAPI/clientApi' ;
2929import { useClientStore } from '../../../../../../hooks/useClientStore' ;
@@ -96,7 +96,9 @@ export const AddInstanceInitForm = () => {
9696 . then ( async ( res : Response ) => {
9797 if ( ! res . ok ) {
9898 setIsLoading ( false ) ;
99- error ( JSON . stringify ( res . status ) ) ;
99+ error (
100+ `Enrollment start returned non-OK status ${ res . status } for URL: ${ endpointUrl } ` ,
101+ ) ;
100102 const errorMessage = ( ( await res . json ( ) ) as EnrollmentError ) . error ;
101103
102104 switch ( errorMessage ) {
@@ -120,9 +122,7 @@ export const AddInstanceInitForm = () => {
120122 if ( ! authCookie ) {
121123 setIsLoading ( false ) ;
122124 error (
123- LL . common . messages . errorWithMessage ( {
124- message : LL . common . messages . noCookie ( ) ,
125- } ) ,
125+ `Enrollment start response for ${ endpointUrl } is missing defguard_proxy set-cookie header` ,
126126 ) ;
127127 throw Error (
128128 LL . common . messages . errorWithMessage ( {
@@ -154,34 +154,57 @@ export const AddInstanceInitForm = () => {
154154 body : JSON . stringify ( {
155155 pubkey : instance . pubkey ,
156156 } ) ,
157- } ) . then ( async ( res ) => {
158- invoke < void > ( 'update_instance' , {
159- instanceId : instance . id ,
160- response : ( await res . json ( ) ) as CreateDeviceResponse ,
161- } )
162- . then ( ( ) => {
163- info ( 'Configured device' ) ;
164- toaster . success (
165- LL . pages . enrollment . steps . deviceSetup . desktopSetup . messages . deviceConfigured ( ) ,
166- ) ;
167- const _selectedInstance : SelectedInstance = {
168- id : instance . id ,
169- type : ClientConnectionType . LOCATION ,
170- } ;
171- setClientState ( {
172- selectedInstance : _selectedInstance ,
173- } ) ;
174- navigate ( routes . client . base , { replace : true } ) ;
175- } )
176- . catch ( ( e ) => {
177- error ( e ) ;
157+ } )
158+ . then ( async ( res ) => {
159+ if ( ! res . ok ) {
160+ const detail = `network_info returned status ${ res . status } for instance ${ instance . uuid } ` ;
161+ error ( `Failed to fetch network info: ${ detail } ` ) ;
178162 toaster . error (
179163 LL . common . messages . errorWithMessage ( {
180- message : String ( e ) ,
164+ message : detail ,
181165 } ) ,
182166 ) ;
183- } ) ;
184- } ) ;
167+ return ;
168+ }
169+ invoke < void > ( 'update_instance' , {
170+ instanceId : instance . id ,
171+ response : ( await res . json ( ) ) as CreateDeviceResponse ,
172+ } )
173+ . then ( ( ) => {
174+ info ( 'Configured device' ) ;
175+ toaster . success (
176+ LL . pages . enrollment . steps . deviceSetup . desktopSetup . messages . deviceConfigured ( ) ,
177+ ) ;
178+ const _selectedInstance : SelectedInstance = {
179+ id : instance . id ,
180+ type : ClientConnectionType . LOCATION ,
181+ } ;
182+ setClientState ( {
183+ selectedInstance : _selectedInstance ,
184+ } ) ;
185+ navigate ( routes . client . base , { replace : true } ) ;
186+ } )
187+ . catch ( ( e ) => {
188+ const detail = errorDetail ( e ) ;
189+ error ( `Failed to save config during instance add: ${ detail } ` ) ;
190+ toaster . error (
191+ LL . common . messages . errorWithMessage ( {
192+ message : String ( e ) ,
193+ } ) ,
194+ ) ;
195+ } ) ;
196+ } )
197+ . catch ( ( e ) => {
198+ const detail = errorDetail ( e ) ;
199+ error (
200+ `Failed to reach network_info endpoint for instance ${ instance . uuid } : ${ detail } ` ,
201+ ) ;
202+ toaster . error (
203+ LL . common . messages . errorWithMessage ( {
204+ message : String ( e ) ,
205+ } ) ,
206+ ) ;
207+ } ) ;
185208 }
186209 // register new instance
187210 // is user in need of full enrollment ?
@@ -220,6 +243,8 @@ export const AddInstanceInitForm = () => {
220243 } )
221244 . catch ( ( e ) => {
222245 setIsLoading ( false ) ;
246+ const detail = errorDetail ( e ) ;
247+ error ( `Failed to initialize instance: ${ detail } ` ) ;
223248 if ( typeof e === 'string' ) {
224249 if ( e . includes ( 'Network Error' ) ) {
225250 toaster . error ( LL . common . messages . networkError ( ) ) ;
0 commit comments