@naturalcycles/nodejs-lib 12.101.0 → 12.101.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.
@@ -14,6 +14,7 @@ import { SlackAttachmentField, SlackMessage, SlackServiceCfg } from './slack.ser
14
14
  */
15
15
  export declare class SlackService<CTX = any> {
16
16
  constructor(cfg: Partial<SlackServiceCfg<CTX>>);
17
+ private fetcher;
17
18
  cfg: SlackServiceCfg<CTX>;
18
19
  /**
19
20
  * Allows to "log" many things at once, similar to `console.log(one, two, three).
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.slackDefaultMessagePrefixHook = exports.SlackService = void 0;
4
4
  const js_lib_1 = require("@naturalcycles/js-lib");
5
- const got_1 = require("got");
6
5
  const __1 = require("..");
7
6
  const GAE = !!process.env['GAE_INSTANCE'];
8
7
  const DEFAULTS = {
@@ -38,6 +37,9 @@ class SlackService {
38
37
  ...cfg.inspectOptions,
39
38
  },
40
39
  };
40
+ this.fetcher = (0, js_lib_1.getFetcher)({
41
+ timeoutSeconds: 90,
42
+ });
41
43
  }
42
44
  /**
43
45
  * Allows to "log" many things at once, similar to `console.log(one, two, three).
@@ -89,16 +91,18 @@ class SlackService {
89
91
  // Text with Prefix
90
92
  text: [prefix.join(': '), text].filter(Boolean).join('\n'),
91
93
  }, ['items', 'ctx']);
92
- await got_1.default
93
- .post(webhookUrl, {
94
+ await this.fetcher
95
+ .postVoid(webhookUrl, {
94
96
  json,
95
- responseType: 'text',
96
- timeout: 90000,
97
97
  })
98
98
  .catch(err => {
99
99
  // ignore (unless throwOnError is set)
100
- if (msg.throwOnError)
100
+ if (msg.throwOnError) {
101
101
  throw err;
102
+ }
103
+ else {
104
+ console.log(err);
105
+ }
102
106
  });
103
107
  }
104
108
  kvToFields(kv) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
- "version": "12.101.0",
3
+ "version": "12.101.2",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "docs-serve": "vuepress dev docs",
@@ -4,10 +4,11 @@ import {
4
4
  CommonLogger,
5
5
  commonLoggerMinLevel,
6
6
  CommonLogLevel,
7
+ Fetcher,
8
+ getFetcher,
7
9
  localTime,
8
10
  PQueue,
9
11
  } from '@naturalcycles/js-lib'
10
- import got from 'got'
11
12
  import { inspectAny, InspectAnyOptions } from '..'
12
13
  import {
13
14
  SlackApiBody,
@@ -53,8 +54,14 @@ export class SlackService<CTX = any> {
53
54
  ...cfg.inspectOptions,
54
55
  },
55
56
  }
57
+
58
+ this.fetcher = getFetcher({
59
+ timeoutSeconds: 90,
60
+ })
56
61
  }
57
62
 
63
+ private fetcher: Fetcher
64
+
58
65
  cfg!: SlackServiceCfg<CTX>
59
66
 
60
67
  /**
@@ -120,15 +127,17 @@ export class SlackService<CTX = any> {
120
127
  ['items', 'ctx'],
121
128
  )
122
129
 
123
- await got
124
- .post(webhookUrl, {
130
+ await this.fetcher
131
+ .postVoid(webhookUrl, {
125
132
  json,
126
- responseType: 'text',
127
- timeout: 90_000,
128
133
  })
129
134
  .catch(err => {
130
135
  // ignore (unless throwOnError is set)
131
- if (msg.throwOnError) throw err
136
+ if (msg.throwOnError) {
137
+ throw err
138
+ } else {
139
+ console.log(err)
140
+ }
132
141
  })
133
142
  }
134
143