Skip to content

Commit bd273ca

Browse files
authored
chore: add a temporary catch for unknown error (#1257)
## Problem Telegram is timing out for some reason but with an unknown error, so it's not automatically retrying ## Solution Temporarily log entire error. Try retrying if generic error.
1 parent adeedf1 commit bd273ca

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

packages/backend/src/apps/telegram-bot/common/throw-errors.ts

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import get from 'lodash.get'
55
import HttpError from '@/errors/http'
66
import RetriableError from '@/errors/retriable-error'
77
import StepError from '@/errors/step'
8+
import logger from '@/helpers/logger'
89
import Step, { StepContext } from '@/models/step'
910

1011
export async function throwSendMessageError(
@@ -14,16 +15,34 @@ export async function throwSendMessageError(
1415
testRun: boolean,
1516
): Promise<never> {
1617
const position = step.position
18+
logger.error('Telegram bot error', {
19+
error: err,
20+
})
1721
// catch telegram errors with different error format for ETIMEDOUT and ECONNRESET: e.g. details: { error: 'connect ECONNREFUSED 127.0.0.1:3002' }
1822
const errorString = JSON.stringify(get(err, 'details.error', ''))
19-
if (errorString.includes('ECONNRESET') || errorString.includes('ETIMEDOUT')) {
20-
throw new StepError(
21-
'Connection issues',
22-
'Please retry in a few minutes because telegram is currently experiencing issues.',
23-
position,
24-
appName,
25-
err,
26-
)
23+
if (
24+
errorString.includes('ECONNRESET') ||
25+
errorString.includes('ETIMEDOUT') ||
26+
err.message.includes('ETIMEDOUT') ||
27+
err.code === 'ETIMEDOUT'
28+
) {
29+
throw new RetriableError({
30+
error: 'Timeout error. Telegram may be experiencing issues.',
31+
delayInMs: 'default',
32+
delayType: 'step',
33+
})
34+
}
35+
36+
/**
37+
* TODO: Temporary error handling since I cant find a way to catch the ETIMEDOUT error
38+
*/
39+
const errorDetails = JSON.stringify(get(err, 'details', {}))
40+
if (errorDetails === '{"error": "Error"}') {
41+
throw new RetriableError({
42+
error: 'Timeout error. Telegram may be experiencing issues.',
43+
delayInMs: 'default',
44+
delayType: 'step',
45+
})
2746
}
2847

2948
// catch telegram errors with proper http error format

packages/backend/src/errors/http.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import BaseError from './base'
66

77
export default class HttpError extends BaseError {
88
response: AxiosResponse
9+
code?: string
910

1011
constructor(error: AxiosError) {
1112
const computedError =
@@ -22,6 +23,9 @@ export default class HttpError extends BaseError {
2223
headers: {},
2324
}
2425

26+
// Pass code along
27+
this.code = error.code
28+
2529
//
2630
// Only preserve selected headers to avoid storing sensitive data.
2731
//

0 commit comments

Comments
 (0)