Removed timing request for the webhook.
This commit is contained in:
1 parent
55c1a1c233
commit
ff2b3b4e10
1 file changed
+29
-35
@@ -437,46 +437,40 @@ class NetworkService {
|
|||||||
|
|
||||||
async requestWebhook(platform, url, message) {
|
async requestWebhook(platform, url, message) {
|
||||||
try {
|
try {
|
||||||
const { response, responseTime, error } = await this.timeRequest(() =>
|
const response = await this.axios.post(url, message, {
|
||||||
this.axios.post(url, message, {
|
headers: {
|
||||||
headers: {
|
'Content-Type': 'application/json'
|
||||||
'Content-Type': 'application/json'
|
}
|
||||||
}
|
});
|
||||||
})
|
|
||||||
);
|
|
||||||
|
|
||||||
const webhookResponse = {
|
return {
|
||||||
type: 'webhook',
|
type: 'webhook',
|
||||||
responseTime,
|
status: true,
|
||||||
payload: response?.data
|
code: response.status,
|
||||||
|
message: `Successfully sent ${platform} notification`,
|
||||||
|
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) {
|
} catch (error) {
|
||||||
error.service = this.SERVICE_NAME;
|
this.logger.warn({
|
||||||
error.method = 'requestWebhook';
|
message: error.message,
|
||||||
throw error;
|
service: this.SERVICE_NAME,
|
||||||
|
method: 'requestWebhook',
|
||||||
|
url,
|
||||||
|
platform,
|
||||||
|
error: error.message,
|
||||||
|
statusCode: error.response?.status,
|
||||||
|
responseData: error.response?.data,
|
||||||
|
requestPayload: message
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: 'webhook',
|
||||||
|
status: false,
|
||||||
|
code: error.response?.status || this.NETWORK_ERROR,
|
||||||
|
message: `Failed to send ${platform} notification`,
|
||||||
|
payload: error.response?.data
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user