@@ -3,14 +3,17 @@ import axios from "./Axios";
33import { ConfigsProps } from "../context/reducers/appReducer" ;
44import { RoomProps } from "../context/reducers/roomsReducer" ;
55import PackageJson from "../../package.json" ;
6+ import * as events from "../utils/events" ;
67
78export interface InitiateProps {
89 apiKey : string ;
910 subscriptionKey : string ;
11+ projectName : string ;
1012}
1113
1214interface OnlineInfoProps extends InitiateProps {
1315 userIds : string ;
16+ chatAuthId : string ; // for selfUser's chatAuthId
1417}
1518
1619type OnlineInfoReturnProps = Pick <
@@ -20,20 +23,30 @@ type OnlineInfoReturnProps = Pick<
2023
2124interface ReadTokenProps extends InitiateProps {
2225 roomIds : string ;
26+ chatAuthId : string ; //selfUser's chatAuthId
2327}
2428
2529type ReadTokenReturnProps = Pick <
2630 RoomProps ,
2731 "chatRoomAuthId" | "lastMessageReadToken"
2832> ;
2933
34+ interface HandleLoggerProps extends InitiateProps {
35+ error : {
36+ error : Error | string | { [ key : string ] : any } | unknown ;
37+ event : string ;
38+ } ;
39+ chatAuthId ?: string ;
40+ chatRoomAuthId ?: string ;
41+ }
42+
3043const project = {
3144 name : "React Native SDK" ,
3245 version : PackageJson . version ,
3346} ;
3447
3548export const initiate = async ( props : InitiateProps ) => {
36- const { apiKey, subscriptionKey } = props ;
49+ const { apiKey, subscriptionKey, projectName } = props ;
3750
3851 try {
3952 const response = await axios . get < ConfigsProps > ( `/api/v1/tenant/config/` , {
@@ -53,14 +66,22 @@ export const initiate = async (props: InitiateProps) => {
5366 }
5467
5568 return ;
56- } catch {
57- // TODO: Log error
58- /* empty */
69+ } catch ( error ) {
70+ // Log error to service
71+ handleLogger ( {
72+ apiKey,
73+ subscriptionKey,
74+ projectName,
75+ error : {
76+ error,
77+ event : events . INITIATE_TENANT_CONFIGS ,
78+ } ,
79+ } ) ;
5980 }
6081} ;
6182
6283export const getUsersOnlineInfo = async ( props : OnlineInfoProps ) => {
63- const { userIds, apiKey, subscriptionKey } = props ;
84+ const { userIds, apiKey, subscriptionKey, projectName , chatAuthId } = props ;
6485
6586 try {
6687 const response = await axios . get < OnlineInfoReturnProps [ ] > (
@@ -77,14 +98,23 @@ export const getUsersOnlineInfo = async (props: OnlineInfoProps) => {
7798 ) ;
7899
79100 return response . data ;
80- } catch {
81- // TODO: Log error
82- /* empty */
101+ } catch ( error ) {
102+ // Log error to service
103+ handleLogger ( {
104+ apiKey,
105+ subscriptionKey,
106+ projectName,
107+ error : {
108+ error,
109+ event : events . GET_USERS_ONLINE_INFO ,
110+ } ,
111+ chatAuthId,
112+ } ) ;
83113 }
84114} ;
85115
86116export const getRoomsReadToken = async ( props : ReadTokenProps ) => {
87- const { roomIds, apiKey, subscriptionKey } = props ;
117+ const { roomIds, apiKey, subscriptionKey, projectName , chatAuthId } = props ;
88118
89119 try {
90120 const response = await axios . get < ReadTokenReturnProps [ ] > (
@@ -100,8 +130,49 @@ export const getRoomsReadToken = async (props: ReadTokenProps) => {
100130 } ,
101131 ) ;
102132 return response . data ;
103- } catch {
133+ } catch ( error ) {
104134 // TODO: Log error
105- /* empty */
135+ handleLogger ( {
136+ apiKey,
137+ subscriptionKey,
138+ projectName,
139+ error : {
140+ error,
141+ event : events . GET_ROOMS_READ_TOKEN ,
142+ } ,
143+ chatAuthId,
144+ } ) ;
145+ }
146+ } ;
147+
148+ export const handleLogger = async ( props : HandleLoggerProps ) => {
149+ const {
150+ apiKey,
151+ subscriptionKey,
152+ projectName,
153+ error,
154+ chatAuthId,
155+ chatRoomAuthId,
156+ } = props ;
157+
158+ const logObject = {
159+ projectName,
160+ SDK : project . name ,
161+ version : project . version ,
162+ error,
163+ ...( chatAuthId && { chatAuthId } ) ,
164+ ...( chatRoomAuthId && { chatRoomAuthId } ) ,
165+ } ;
166+
167+ try {
168+ axios . post ( "/system/logger" , logObject , {
169+ headers : {
170+ apiKey,
171+ subscriptionKey,
172+ } ,
173+ } ) ;
174+ } catch ( error_ ) {
175+ // Log error
176+ console . log ( "handle Logger failed" , error_ ) ;
106177 }
107178} ;
0 commit comments