Use the NetworkService for making network requests.

This commit is contained in:
Skorpios committed 2025-02-01 23:06:35 -08:00
1 parent 92d9573fcf
commit cc48f1d3aa
3 files changed
+104 -46

No files matched your search

+46
View File
@@ -336,6 +336,52 @@ class NetworkService {
throw err;
}
async requestWebhook(platform, url, message) {
try {
const { response, responseTime, error } = await this.timeRequest(() =>
this.axios.post(url, message, {
headers: {
'Content-Type': 'application/json'
}
})
);
const webhookResponse = {
type: 'webhook',
responseTime,
payload: response?.data
};
if (error) {
webhookResponse.status = false;
webhookResponse.code = error.response?.status || this.NETWORK_ERROR;
webhookResponse.message = `Failed to send ${platform} notification`;
this.logger.warn({
message: error.message,
service: this.SERVICE_NAME,
method: 'requestWebhook',
url,
platform,
error: error.message,
statusCode: error.response?.status,
responseData: error.response?.data,
requestPayload: message
});
return webhookResponse;
}
webhookResponse.status = true;
webhookResponse.code = response.status;
webhookResponse.message = `Successfully sent ${platform} notification`;
return webhookResponse;
} catch (error) {
error.service = this.SERVICE_NAME;
error.method = 'requestWebhook';
throw error;
}
}
/**
* Gets the status of a job based on its type and returns the appropriate response.
*