mirror of
https://github.com/mohamadihsan/topuponline.git
synced 2026-12-05 10:46:28 +00:00
Handle missing CTS configuration and request failures
This commit is contained in:
@@ -295,8 +295,20 @@ const validateReplacement = async (req, res) => {
|
||||
|
||||
// if (is_warranty == true) {
|
||||
let result = {};
|
||||
const ctsUrl = process.env.CTS_URL?.trim();
|
||||
if (!ctsUrl) {
|
||||
return res.status(200).json({
|
||||
code: '500',
|
||||
message: 'CTS connection has not been configured.',
|
||||
data: {
|
||||
status: false,
|
||||
detail: {},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// const baseUrl = 'https://appdev.kci.id/cts/v2/api/info/last-balance'
|
||||
const baseUrl = `${process.env.CTS_URL}/v2/api/info/last-balance`;
|
||||
const baseUrl = `${ctsUrl}/v2/api/info/last-balance`;
|
||||
const payload = {
|
||||
card_number: card_number,
|
||||
};
|
||||
@@ -306,7 +318,22 @@ const validateReplacement = async (req, res) => {
|
||||
},
|
||||
};
|
||||
const url = baseUrl;
|
||||
const response = await postWithDeadline(url, payload, config);
|
||||
let response;
|
||||
try {
|
||||
response = await postWithDeadline(url, payload, config);
|
||||
} catch (error) {
|
||||
winston.logger.warn(
|
||||
`${logCorrelation(uniqueCode)} [ CTS REQUEST FAILED ] error_code=${logErrorCode(error)}`
|
||||
);
|
||||
return res.status(200).json({
|
||||
code: '415',
|
||||
message: 'Failed to retrieve last balance from CTS.',
|
||||
data: {
|
||||
status: false,
|
||||
detail: {},
|
||||
},
|
||||
});
|
||||
}
|
||||
if (response.data.code == undefined || response.data.code != 200) {
|
||||
if (response.data.code == 404) {
|
||||
result = {
|
||||
@@ -324,7 +351,7 @@ const validateReplacement = async (req, res) => {
|
||||
}
|
||||
result = {
|
||||
code: '415',
|
||||
message: 'Last Balance not updated.',
|
||||
message: 'Failed to retrieve last balance from CTS.',
|
||||
data: {
|
||||
status: false,
|
||||
detail: {},
|
||||
|
||||
Reference in New Issue
Block a user