feat(logging): enhance error logging in webhook retry and Telegram message sending
Add detailed logging for error reasons and codes in the retryFailedWebhook function. Improve error handling in sendTelegramMessage by creating a more informative error message and logging additional response details. Update the releasehook endpoint to handle Telegram message sending synchronously, allowing for better error response management.
This commit is contained in:
@@ -15,6 +15,7 @@ async function retryFailedWebhook(filepath) {
|
||||
const payload = data.payload;
|
||||
|
||||
console.log(`Repository: ${payload?.repository?.name || 'unknown'}`);
|
||||
console.log(`Original failure reason: ${data.reason || 'unknown'}`);
|
||||
console.log(`Original error: ${data.error}`);
|
||||
console.log(`Failed at: ${data.timestamp}`);
|
||||
|
||||
@@ -45,6 +46,14 @@ async function retryFailedWebhook(filepath) {
|
||||
console.log(`Response status: ${error.response.status}`);
|
||||
console.log(`Response data:`, error.response.data);
|
||||
}
|
||||
if (error.code) {
|
||||
console.log(`Error code: ${error.code}`);
|
||||
}
|
||||
if (error.config) {
|
||||
console.log(`Request URL: ${error.config.url}`);
|
||||
console.log(`Request method: ${error.config.method}`);
|
||||
}
|
||||
console.log(`Full error details:`, error.toJSON ? error.toJSON() : error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
38
x.js
38
x.js
@@ -282,6 +282,8 @@ async function sendTelegramMessage(message) {
|
||||
|
||||
try {
|
||||
const url = `https://api.telegram.org/bot${botToken}/sendMessage`;
|
||||
logMessage(`Sending Telegram message: ${message}`, 'info');
|
||||
|
||||
const response = await axios.post(url, {
|
||||
chat_id: chatId,
|
||||
text: message,
|
||||
@@ -295,9 +297,17 @@ async function sendTelegramMessage(message) {
|
||||
logMessage(`Failed to send Telegram message: ${error.message}`, 'error');
|
||||
if (error.response) {
|
||||
logMessage(`Telegram API error: ${JSON.stringify(error.response.data)}`, 'error');
|
||||
logMessage(`Telegram API status: ${error.response.status}`, 'error');
|
||||
}
|
||||
// Re-throw the error so it can be caught by the calling code
|
||||
throw error;
|
||||
|
||||
// Create a more detailed error for webhook failure logging
|
||||
const detailedError = new Error(`Telegram API error: ${error.message}`);
|
||||
if (error.response && error.response.data) {
|
||||
detailedError.message = `Telegram API error (${error.response.status}): ${JSON.stringify(error.response.data)}`;
|
||||
}
|
||||
|
||||
// Re-throw the detailed error so it can be caught by the calling code
|
||||
throw detailedError;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -354,7 +364,7 @@ function formatCommitMessage(payload) {
|
||||
// Replace raw hyphen with EN DASH between hash and message to avoid '-' entity errors
|
||||
commitsText += `\n🔧 \`${hashInline}\` – ${escapedMessage}`;
|
||||
if (commits.length > 1) {
|
||||
commitsText += ` (${escapeMdV2(author)})`;
|
||||
commitsText += ` \\(${escapeMdV2(author)}\\)`;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -437,7 +447,7 @@ ${compare ? `\n${compare}` : ''}${summaryBlock}`;
|
||||
|
||||
app.use(bodyParser.json());
|
||||
|
||||
app.post('/releasehook_kjfhdkf987987', (req, res) => {
|
||||
app.post('/releasehook_kjfhdkf987987', async (req, res) => {
|
||||
try {
|
||||
const payload = req.body;
|
||||
logMessage(`Webhook received for repository: ${payload?.repository?.name || 'unknown'}`);
|
||||
@@ -445,14 +455,20 @@ app.post('/releasehook_kjfhdkf987987', (req, res) => {
|
||||
// Log the complete payload for analysis
|
||||
logMessage(`Complete payload received: ${JSON.stringify(payload, null, 2)}`);
|
||||
|
||||
// Send Telegram notification
|
||||
// formatCommitMessage may return a Promise; normalize before sending
|
||||
Promise.resolve(formatCommitMessage(payload))
|
||||
.then((telegramMessage) => sendTelegramMessage(telegramMessage))
|
||||
.catch(error => {
|
||||
logMessage(`Error sending Telegram message: ${error.message}`, 'error');
|
||||
dumpFailedWebhook(payload, error, 'telegram_send_error');
|
||||
// Send Telegram notification synchronously so we can return the error
|
||||
try {
|
||||
const telegramMessage = await Promise.resolve(formatCommitMessage(payload));
|
||||
await sendTelegramMessage(telegramMessage);
|
||||
logMessage('Telegram message sent successfully');
|
||||
} catch (error) {
|
||||
logMessage(`Error sending Telegram message: ${error.message}`, 'error');
|
||||
dumpFailedWebhook(payload, error, 'telegram_send_error');
|
||||
// Return error response instead of 200
|
||||
return res.status(400).json({
|
||||
error: 'Telegram send failed',
|
||||
details: error.message
|
||||
});
|
||||
}
|
||||
|
||||
// Set a flag to track if we've sent a response
|
||||
let responseSent = false;
|
||||
|
||||
Reference in New Issue
Block a user