1- import { FC , FormEvent , useState } from 'react' ;
1+ /* eslint-disable no-console */
22import {
33 IterableEmbeddedManager ,
44 IterableEmbeddedMessageUpdateHandler ,
5- trackEmbeddedSession ,
6- trackEmbeddedReceived ,
5+ IterableResponse ,
76 trackEmbeddedClick ,
8- trackEmbeddedDismiss
7+ trackEmbeddedDismiss ,
8+ trackEmbeddedReceived ,
9+ trackEmbeddedSession
910} from '@iterable/web-sdk' ;
11+ import { AxiosError , AxiosResponse , isAxiosError } from 'axios' ;
12+ import { FC , FormEvent , useState } from 'react' ;
1013import { v4 as uuidv4 } from 'uuid' ;
11- import { TextField } from './TextField' ;
1214import {
13- StyledButton ,
1415 EndpointWrapper ,
1516 Form ,
1617 Heading ,
17- Response
18+ Response ,
19+ StyledButton
1820} from '../views/Components.styled' ;
21+ import { TextField } from './TextField' ;
1922
2023interface Props {
2124 endpointName : string ;
@@ -63,8 +66,10 @@ export const EmbeddedForm: FC<Props> = ({
6366 await embeddedManager . syncMessages ( 'my-website' , ( ) =>
6467 console . log ( 'Synced message' )
6568 ) ;
66- } catch ( error : any ) {
67- setTrackResponse ( JSON . stringify ( error ?. response ?. data ) ) ;
69+ } catch ( error : unknown ) {
70+ setTrackResponse (
71+ JSON . stringify ( isAxiosError ( error ) ? error . response ?. data : error )
72+ ) ;
6873 }
6974 } ;
7075
@@ -80,11 +85,11 @@ export const EmbeddedForm: FC<Props> = ({
8085 } ;
8186
8287 trackEmbeddedReceived ( receivedMessage . messageId , 'my-website' )
83- . then ( ( response : any ) => {
88+ . then ( ( response : AxiosResponse < IterableResponse > ) => {
8489 setTrackResponse ( JSON . stringify ( response . data ) ) ;
8590 setTrackingEvent ( false ) ;
8691 } )
87- . catch ( ( error : any ) => {
92+ . catch ( ( error : AxiosError < IterableResponse > ) => {
8893 setTrackResponse ( JSON . stringify ( error . response . data ) ) ;
8994 setTrackingEvent ( false ) ;
9095 } ) ;
@@ -111,11 +116,11 @@ export const EmbeddedForm: FC<Props> = ({
111116 targetUrl,
112117 appPackageName
113118 } )
114- . then ( ( response : any ) => {
119+ . then ( ( response : AxiosResponse < IterableResponse > ) => {
115120 setTrackResponse ( JSON . stringify ( response . data ) ) ;
116121 setTrackingEvent ( false ) ;
117122 } )
118- . catch ( ( error : any ) => {
123+ . catch ( ( error : AxiosError < IterableResponse > ) => {
119124 setTrackResponse ( JSON . stringify ( error . response . data ) ) ;
120125 setTrackingEvent ( false ) ;
121126 } ) ;
@@ -139,11 +144,11 @@ export const EmbeddedForm: FC<Props> = ({
139144 } ;
140145
141146 trackEmbeddedDismiss ( sessionData )
142- . then ( ( response : any ) => {
147+ . then ( ( response : AxiosResponse < IterableResponse > ) => {
143148 setTrackResponse ( JSON . stringify ( response . data ) ) ;
144149 setTrackingEvent ( false ) ;
145150 } )
146- . catch ( ( error : any ) => {
151+ . catch ( ( error : AxiosError < IterableResponse > ) => {
147152 setTrackResponse ( JSON . stringify ( error . response . data ) ) ;
148153 setTrackingEvent ( false ) ;
149154 } ) ;
@@ -177,11 +182,11 @@ export const EmbeddedForm: FC<Props> = ({
177182 } ;
178183
179184 trackEmbeddedSession ( sessionData )
180- . then ( ( response : any ) => {
185+ . then ( ( response : AxiosResponse < IterableResponse > ) => {
181186 setTrackResponse ( JSON . stringify ( response . data ) ) ;
182187 setTrackingEvent ( false ) ;
183188 } )
184- . catch ( ( error : any ) => {
189+ . catch ( ( error : AxiosError < IterableResponse > ) => {
185190 setTrackResponse ( JSON . stringify ( error . response . data ) ) ;
186191 setTrackingEvent ( false ) ;
187192 } ) ;
0 commit comments