| 1 | const headers = {...args.headers, Authorization: 'Bearer ' + token, 'x-skypetoken': skypeCache.token}; |
| 2 | if (skypeCache.chatService) headers['x-csendpoint'] = skypeCache.chatService; |
| 3 | try { |
| 4 | const response = await fetch(args.url, { |
| 5 | method: args.method, |
| 6 | headers, |
| 7 | body: args.body === null ? undefined : JSON.stringify(args.body), |
| 8 | }); |
| 9 | const text = await response.text(); |
| 10 | let body = text; |
| 11 | try { body = text ? JSON.parse(text) : null; } catch (error) {} |
| 12 | return {status: response.status, retryAfter: response.headers.get('Retry-After'), body}; |
| 13 | } catch (error) { |
| 14 | return {status: 0, body: String(error)}; |
| 15 | } |