@diplodoc/cli 4.22.0-alpha-1 → 4.22.0-alpha-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "author": "Yandex Data UI Team <data-ui@yandex-team.ru>",
4
4
  "description": "Make documentation using yfm-docs in Markdown and HTML formats",
5
5
  "license": "MIT",
6
- "version": "4.22.0-alpha-1",
6
+ "version": "4.22.0-alpha-2",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "git@github.com:diplodoc-platform/cli.git"
@@ -9,7 +9,7 @@ import {LogLevel, Logger} from '~/logger';
9
9
  import {TranslateError, compose, dumpFile, extract, loadFile, resolveSchemas} from '../../utils';
10
10
  import {AuthError, Defer, LimitExceed, RequestError, bytes} from './utils';
11
11
 
12
- const REQUESTS_LIMIT = 20;
12
+ const REQUESTS_LIMIT = 15;
13
13
  const BYTES_LIMIT = 10000;
14
14
  const RETRY_LIMIT = 3;
15
15
 
@@ -44,7 +44,7 @@ export class Provider {
44
44
 
45
45
  const cache = new Map<string, Defer>();
46
46
  const request = requester(translatorParams, cache);
47
- const split = splitter(request, cache);
47
+ const split = splitter(request, cache, this.logger);
48
48
  const translate = translator(translatorParams, split);
49
49
 
50
50
  await eachLimit(
@@ -201,15 +201,21 @@ function requester(params: RequesterParams, cache: Cache) {
201
201
  } catch (error: any) {
202
202
  if (error instanceof AxiosError) {
203
203
  const {response} = error;
204
- const {status, statusText, data} = response as AxiosResponse;
205
-
206
- switch (true) {
207
- case LimitExceed.is(data.message):
208
- throw new LimitExceed(data.message);
209
- case AuthError.is(data.message):
210
- throw new AuthError(data.message);
211
- default:
212
- throw new RequestError(status, statusText, data);
204
+
205
+ if (response) {
206
+ const {status, statusText, data} = response as AxiosResponse;
207
+
208
+ switch (true) {
209
+ case LimitExceed.is(data.message):
210
+ throw new LimitExceed(data.message);
211
+ case AuthError.is(data.message):
212
+ throw new AuthError(data.message);
213
+ default:
214
+ throw new RequestError(status, statusText, data);
215
+ }
216
+ } else {
217
+ console.error(error.code);
218
+ console.error(error.cause);
213
219
  }
214
220
  }
215
221
 
@@ -278,7 +284,7 @@ function translator(params: TranslatorParams, split: Split) {
278
284
  };
279
285
  }
280
286
 
281
- function splitter(request: Request, cache: Cache): Split {
287
+ function splitter(request: Request, cache: Cache, logger: Logger): Split {
282
288
  return async function (path: string, texts: string[]) {
283
289
  const promises: Promise<string>[] = [];
284
290
  const requests: Promise<void>[] = [];
@@ -293,7 +299,7 @@ function splitter(request: Request, cache: Cache): Split {
293
299
 
294
300
  for (const text of texts) {
295
301
  if (text.length >= BYTES_LIMIT) {
296
- // logger.warn(path, 'Skip document part for translation. Part is too big.');
302
+ logger.warn(path, 'Skip document part for translation. Part is too big.');
297
303
  promises.push(Promise.resolve(text));
298
304
  } else {
299
305
  const defer = cache.get(text) || new Defer();