@@ -83,29 +83,35 @@ interface IIKOOrderItem {
8383 comment : string
8484}
8585
86- async function createAccessToken ( ) : Promise < { token : string , correlationId : string } > {
86+ async function createAccessToken ( ) : Promise < string > {
8787 const { iiko } = useRuntimeConfig ( )
8888
8989 const apiUrl = 'https://api-ru.iiko.services/api/1/access_token'
9090 const body = {
9191 apiLogin : iiko . filaApiToken ,
9292 }
9393
94- return fetch ( apiUrl , {
94+ const { token } = await fetch ( apiUrl , {
9595 method : 'POST' ,
9696 headers : {
9797 'Content-Type' : 'application/json' ,
9898 } ,
9999 body : JSON . stringify ( body ) ,
100- } ) . then ( ( res ) => res . json ( ) )
100+ } ) . then ( ( res ) => res . json ( ) ) as { token : string , correlationId : string }
101+
102+ return token
101103}
102104
103105async function sendToIntegration ( data : TildaFilaBody ) {
104106 const logger = useLogger ( 'api:tilda:fila' )
105107 const { iiko } = useRuntimeConfig ( )
106108
107109 try {
108- const { token } = await createAccessToken ( )
110+ const token = await createAccessToken ( )
111+ if ( ! token ) {
112+ logger . error ( 'Failed to create access token' )
113+ throw createError ( { statusCode : 500 , message : 'Failed to create access token' } )
114+ }
109115
110116 const apiUrl = 'https://api-ru.iiko.services/api/1/deliveries/create'
111117
@@ -156,7 +162,7 @@ async function sendToIntegration(data: TildaFilaBody) {
156162 'Authorization' : `Bearer ${ token } ` ,
157163 } ,
158164 body : JSON . stringify ( body ) ,
159- } )
165+ } ) . then ( ( res ) => res . json ( ) )
160166 } catch ( error ) {
161167 logger . error ( error )
162168 }
0 commit comments