|
9 | 9 | import * as path from 'path' |
10 | 10 | import * as fs from 'fs-extra' |
11 | 11 | import {CLIError} from '@microsoft/bf-cli-command' |
| 12 | +import {httpsProxy} from './https-proxy' |
12 | 13 | // eslint-disable-next-line node/no-extraneous-require |
13 | | -const fetch = require('node-fetch') |
| 14 | +const axios = require('axios') |
| 15 | +axios.interceptors.request.use(httpsProxy) |
14 | 16 | const NEWLINE = require('os').EOL |
15 | 17 | const ANY_NEWLINE = /\r\n|\r|\n/g |
16 | 18 |
|
@@ -118,21 +120,20 @@ export class Helper { |
118 | 120 | let tUri = `${baseUri}?api-version=3.0&to=${translateOption.to_lang}&includeAlignment=true` |
119 | 121 | if (translateOption.src_lang) tUri += `&from=${translateOption.src_lang}` |
120 | 122 | const options = { |
121 | | - method: 'POST', |
122 | | - body: JSON.stringify(payload), |
123 | 123 | headers: { |
124 | 124 | 'Content-Type': 'application/json', |
125 | 125 | 'Ocp-Apim-Subscription-Key': translateOption.subscriptionKey, |
126 | 126 | 'Ocp-Apim-Subscription-Region': translateOption.region, |
127 | 127 | 'X-ClientTraceId': Helper.get_guid(), |
128 | 128 | }, |
129 | 129 | } |
130 | | - const res = await fetch(tUri, options) |
131 | | - if (!res.ok) { |
| 130 | + |
| 131 | + const res = await axios.post(tUri, payload, options) |
| 132 | + if (res.status !== 200) { |
132 | 133 | throw (new CLIError('Text translator service call failed with [' + res.status + '] : ' + res.statusText + '.\nPlease check key & language code validity')) |
133 | 134 | } |
134 | 135 |
|
135 | | - const data = await res.json() |
| 136 | + const data = res.data |
136 | 137 | return data |
137 | 138 | } |
138 | 139 |
|
|
0 commit comments