@evanp/activitypub-bot 0.41.1 → 0.41.3

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.
@@ -19,62 +19,62 @@ export class DistributionWorker extends Worker {
19
19
  try {
20
20
  await this.#client.post(inbox, activityObj, username)
21
21
  this._logger.info({ activity: activity.id, inbox }, 'Delivered activity')
22
- } catch (error) {
23
- if (!error.status) {
22
+ } catch (err) {
23
+ if (!err.status) {
24
24
  this._logger.warn(
25
- { error, activity: activity.id, inbox },
25
+ { err, activity: activity.id, inbox },
26
26
  'Could not deliver activity and no HTTP status available')
27
- throw error
28
- } else if (error.status >= 300 && error.status < 400) {
27
+ throw err
28
+ } else if (err.status >= 300 && err.status < 400) {
29
29
  this._logger.warn(
30
- { error, activity: activity.id, inbox },
30
+ { err, activity: activity.id, inbox },
31
31
  'Could not deliver activity and unexpected redirect code'
32
32
  )
33
- throw error
34
- } else if (error.status >= 400 && error.status < 500) {
33
+ throw err
34
+ } else if (err.status >= 400 && err.status < 500) {
35
35
  this._logger.warn(
36
- { error, activity: activity.id, inbox },
36
+ { err, activity: activity.id, inbox },
37
37
  'Could not deliver activity due to client error'
38
38
  )
39
- if ([408, 425, 429].includes(error.status)) {
39
+ if ([408, 425, 429].includes(err.status)) {
40
40
  this._logger.debug(
41
- { error, activity: activity.id, inbox },
41
+ { err, activity: activity.id, inbox },
42
42
  'Retrying on recoverable status'
43
43
  )
44
- const recoverable = new RecoverableError(error.message)
45
- recoverable.delay = this.#retryDelay(error.headers, attempts)
44
+ const recoverable = new RecoverableError(err.message)
45
+ recoverable.delay = this.#retryDelay(err.headers, attempts)
46
46
  throw recoverable
47
47
  } else {
48
- throw error
48
+ throw err
49
49
  }
50
- } else if (error.status >= 500 && error.status < 600) {
51
- if ([501, 505, 508, 510].includes(error.status)) {
50
+ } else if (err.status >= 500 && err.status < 600) {
51
+ if ([501, 505, 508, 510].includes(err.status)) {
52
52
  this._logger.warn(
53
- { error, activity: activity.id, inbox, attempts },
53
+ { err, activity: activity.id, inbox, attempts },
54
54
  'Could not deliver activity due to unrecoverable server error'
55
55
  )
56
- throw error
56
+ throw err
57
57
  } else if (attempts >= DistributionWorker.#MAX_ATTEMPTS) {
58
58
  this._logger.warn(
59
- { error, activity: activity.id, inbox, attempts },
59
+ { err, activity: activity.id, inbox, attempts },
60
60
  'Could not deliver activity due to server error; no more attempts'
61
61
  )
62
- throw error
62
+ throw err
63
63
  } else {
64
- const recoverable = new RecoverableError(error.message)
65
- recoverable.delay = this.#retryDelay(error.headers, attempts)
64
+ const recoverable = new RecoverableError(err.message)
65
+ recoverable.delay = this.#retryDelay(err.headers, attempts)
66
66
  this._logger.warn(
67
- { error, activity: activity.id, inbox, attempts, delay: recoverable.delay },
67
+ { err, activity: activity.id, inbox, attempts, delay: recoverable.delay },
68
68
  'Could not deliver activity due to server error; will retry'
69
69
  )
70
70
  throw recoverable
71
71
  }
72
72
  } else {
73
73
  this._logger.warn(
74
- { error, activity: activity.id, inbox },
74
+ { err, activity: activity.id, inbox },
75
75
  'Could not deliver activity due to unexpected status range'
76
76
  )
77
- throw error
77
+ throw err
78
78
  }
79
79
  }
80
80
  }
package/lib/safeagent.js CHANGED
@@ -27,7 +27,16 @@ export class SafeAgent extends https.Agent {
27
27
  if (isPrivateIP(address)) {
28
28
  return callback(new PrivateNetworkError(address))
29
29
  }
30
- super.createConnection({ ...options, hostname: address }, callback)
30
+ try {
31
+ const socket = super.createConnection({
32
+ ...options,
33
+ host: address,
34
+ servername: options.servername || options.hostname
35
+ })
36
+ callback(null, socket)
37
+ } catch (e) {
38
+ callback(e)
39
+ }
31
40
  })
32
41
  }
33
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evanp/activitypub-bot",
3
- "version": "0.41.1",
3
+ "version": "0.41.3",
4
4
  "description": "server-side ActivityPub bot framework",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",