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;
|
const payload = data.payload;
|
||||||
|
|
||||||
console.log(`Repository: ${payload?.repository?.name || 'unknown'}`);
|
console.log(`Repository: ${payload?.repository?.name || 'unknown'}`);
|
||||||
|
console.log(`Original failure reason: ${data.reason || 'unknown'}`);
|
||||||
console.log(`Original error: ${data.error}`);
|
console.log(`Original error: ${data.error}`);
|
||||||
console.log(`Failed at: ${data.timestamp}`);
|
console.log(`Failed at: ${data.timestamp}`);
|
||||||
|
|
||||||
@@ -45,6 +46,14 @@ async function retryFailedWebhook(filepath) {
|
|||||||
console.log(`Response status: ${error.response.status}`);
|
console.log(`Response status: ${error.response.status}`);
|
||||||
console.log(`Response data:`, error.response.data);
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
34
x.js
34
x.js
@@ -282,6 +282,8 @@ async function sendTelegramMessage(message) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const url = `https://api.telegram.org/bot${botToken}/sendMessage`;
|
const url = `https://api.telegram.org/bot${botToken}/sendMessage`;
|
||||||
|
logMessage(`Sending Telegram message: ${message}`, 'info');
|
||||||
|
|
||||||
const response = await axios.post(url, {
|
const response = await axios.post(url, {
|
||||||
chat_id: chatId,
|
chat_id: chatId,
|
||||||
text: message,
|
text: message,
|
||||||
@@ -295,9 +297,17 @@ async function sendTelegramMessage(message) {
|
|||||||
logMessage(`Failed to send Telegram message: ${error.message}`, 'error');
|
logMessage(`Failed to send Telegram message: ${error.message}`, 'error');
|
||||||
if (error.response) {
|
if (error.response) {
|
||||||
logMessage(`Telegram API error: ${JSON.stringify(error.response.data)}`, 'error');
|
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
|
// Replace raw hyphen with EN DASH between hash and message to avoid '-' entity errors
|
||||||
commitsText += `\n🔧 \`${hashInline}\` – ${escapedMessage}`;
|
commitsText += `\n🔧 \`${hashInline}\` – ${escapedMessage}`;
|
||||||
if (commits.length > 1) {
|
if (commits.length > 1) {
|
||||||
commitsText += ` (${escapeMdV2(author)})`;
|
commitsText += ` \\(${escapeMdV2(author)}\\)`;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -437,7 +447,7 @@ ${compare ? `\n${compare}` : ''}${summaryBlock}`;
|
|||||||
|
|
||||||
app.use(bodyParser.json());
|
app.use(bodyParser.json());
|
||||||
|
|
||||||
app.post('/releasehook_kjfhdkf987987', (req, res) => {
|
app.post('/releasehook_kjfhdkf987987', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const payload = req.body;
|
const payload = req.body;
|
||||||
logMessage(`Webhook received for repository: ${payload?.repository?.name || 'unknown'}`);
|
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
|
// Log the complete payload for analysis
|
||||||
logMessage(`Complete payload received: ${JSON.stringify(payload, null, 2)}`);
|
logMessage(`Complete payload received: ${JSON.stringify(payload, null, 2)}`);
|
||||||
|
|
||||||
// Send Telegram notification
|
// Send Telegram notification synchronously so we can return the error
|
||||||
// formatCommitMessage may return a Promise; normalize before sending
|
try {
|
||||||
Promise.resolve(formatCommitMessage(payload))
|
const telegramMessage = await Promise.resolve(formatCommitMessage(payload));
|
||||||
.then((telegramMessage) => sendTelegramMessage(telegramMessage))
|
await sendTelegramMessage(telegramMessage);
|
||||||
.catch(error => {
|
logMessage('Telegram message sent successfully');
|
||||||
|
} catch (error) {
|
||||||
logMessage(`Error sending Telegram message: ${error.message}`, 'error');
|
logMessage(`Error sending Telegram message: ${error.message}`, 'error');
|
||||||
dumpFailedWebhook(payload, error, 'telegram_send_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
|
// Set a flag to track if we've sent a response
|
||||||
let responseSent = false;
|
let responseSent = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user