naga-audit-service
Version:
A comprehensive audit service library for NestJS applications with MongoDB support
37 lines • 1.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.sendRequestToService = sendRequestToService;
const custom_error_exception_1 = require("../errors/custom-error.exception");
const axios_wrapper_1 = require("./axios-wrapper");
async function sendRequestToService({ method, service, requestPath, query = {}, throwException = true, timeout, retries = 3, retryDelay = 1000, }) {
try {
const response = await (0, axios_wrapper_1.interServiceRequestHelper)({
method: 'get',
service,
requestPath,
query,
throwException,
timeout,
retries,
retryDelay
});
return response;
}
catch (error) {
let errorMessage = 'SOMETHING_WENT_WRONG';
let statusCode = 500;
if (error.response?.data?.message) {
errorMessage = error.response.data.message;
statusCode = error.response.status || statusCode;
}
else if (error.message) {
errorMessage = error.message;
statusCode = error.status || statusCode;
}
if (throwException) {
throw new custom_error_exception_1.ErrorException(null, errorMessage, statusCode);
}
return null;
}
}
//# sourceMappingURL=inter-service-gateway.js.map