@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.
- package/lib/distributionworker.js +25 -25
- package/lib/safeagent.js +10 -1
- package/package.json +1 -1
|
@@ -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 (
|
|
23
|
-
if (!
|
|
22
|
+
} catch (err) {
|
|
23
|
+
if (!err.status) {
|
|
24
24
|
this._logger.warn(
|
|
25
|
-
{
|
|
25
|
+
{ err, activity: activity.id, inbox },
|
|
26
26
|
'Could not deliver activity and no HTTP status available')
|
|
27
|
-
throw
|
|
28
|
-
} else if (
|
|
27
|
+
throw err
|
|
28
|
+
} else if (err.status >= 300 && err.status < 400) {
|
|
29
29
|
this._logger.warn(
|
|
30
|
-
{
|
|
30
|
+
{ err, activity: activity.id, inbox },
|
|
31
31
|
'Could not deliver activity and unexpected redirect code'
|
|
32
32
|
)
|
|
33
|
-
throw
|
|
34
|
-
} else if (
|
|
33
|
+
throw err
|
|
34
|
+
} else if (err.status >= 400 && err.status < 500) {
|
|
35
35
|
this._logger.warn(
|
|
36
|
-
{
|
|
36
|
+
{ err, activity: activity.id, inbox },
|
|
37
37
|
'Could not deliver activity due to client error'
|
|
38
38
|
)
|
|
39
|
-
if ([408, 425, 429].includes(
|
|
39
|
+
if ([408, 425, 429].includes(err.status)) {
|
|
40
40
|
this._logger.debug(
|
|
41
|
-
{
|
|
41
|
+
{ err, activity: activity.id, inbox },
|
|
42
42
|
'Retrying on recoverable status'
|
|
43
43
|
)
|
|
44
|
-
const recoverable = new RecoverableError(
|
|
45
|
-
recoverable.delay = this.#retryDelay(
|
|
44
|
+
const recoverable = new RecoverableError(err.message)
|
|
45
|
+
recoverable.delay = this.#retryDelay(err.headers, attempts)
|
|
46
46
|
throw recoverable
|
|
47
47
|
} else {
|
|
48
|
-
throw
|
|
48
|
+
throw err
|
|
49
49
|
}
|
|
50
|
-
} else if (
|
|
51
|
-
if ([501, 505, 508, 510].includes(
|
|
50
|
+
} else if (err.status >= 500 && err.status < 600) {
|
|
51
|
+
if ([501, 505, 508, 510].includes(err.status)) {
|
|
52
52
|
this._logger.warn(
|
|
53
|
-
{
|
|
53
|
+
{ err, activity: activity.id, inbox, attempts },
|
|
54
54
|
'Could not deliver activity due to unrecoverable server error'
|
|
55
55
|
)
|
|
56
|
-
throw
|
|
56
|
+
throw err
|
|
57
57
|
} else if (attempts >= DistributionWorker.#MAX_ATTEMPTS) {
|
|
58
58
|
this._logger.warn(
|
|
59
|
-
{
|
|
59
|
+
{ err, activity: activity.id, inbox, attempts },
|
|
60
60
|
'Could not deliver activity due to server error; no more attempts'
|
|
61
61
|
)
|
|
62
|
-
throw
|
|
62
|
+
throw err
|
|
63
63
|
} else {
|
|
64
|
-
const recoverable = new RecoverableError(
|
|
65
|
-
recoverable.delay = this.#retryDelay(
|
|
64
|
+
const recoverable = new RecoverableError(err.message)
|
|
65
|
+
recoverable.delay = this.#retryDelay(err.headers, attempts)
|
|
66
66
|
this._logger.warn(
|
|
67
|
-
{
|
|
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
|
-
{
|
|
74
|
+
{ err, activity: activity.id, inbox },
|
|
75
75
|
'Could not deliver activity due to unexpected status range'
|
|
76
76
|
)
|
|
77
|
-
throw
|
|
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
|
-
|
|
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
|
}
|