Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4 from ONEST-Network/bap-client-time-logging
Browse files Browse the repository at this point in the history
Performance enhancements
  • Loading branch information
maheshkumargangula authored May 21, 2024
2 parents 8f67a96 + a1eaeb2 commit bcaf13a
Show file tree
Hide file tree
Showing 7 changed files with 195 additions and 167 deletions.
106 changes: 43 additions & 63 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"cors": "^2.8.5",
"dotenv": "^16.4.1",
"express": "^4.18.1",
"express-openapi-validator": "^4.13.8",
"express-openapi-validator": "^5.1.6",
"ioredis": "^5.0.6",
"libsodium-wrappers": "^0.7.9",
"lodash": "^4.17.21",
Expand Down
100 changes: 64 additions & 36 deletions src/controllers/bap.trigger.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ export const bapClientTriggerSettler = async (

const context = JSON.parse(JSON.stringify(requestBody.context));
const axios_config = await createAuthHeaderConfig(requestBody);

const bpp_id = requestBody.context.bpp_id;
const bpp_uri = requestBody.context.bpp_uri;
const action = requestBody.context.action;
Expand All @@ -122,72 +121,101 @@ export const bapClientTriggerSettler = async (
for (let i = 0; i < subscribers!.length; i++) {
subscribers![i].subscriber_url = bpp_uri;
}

response = await callNetwork(
callNetwork(
subscribers!,
requestBody,
axios_config,
action
);
).then((response) => {
responseHandler(response, requestBody, action);
});
} else {
const subscribers = await registryLookup({
type: NetworkPaticipantType.BG,
domain: requestBody.context.domain
});

response = await callNetwork(
callNetwork(
subscribers!,
requestBody,
axios_config,
action
).then((response) => {
responseHandler(response, requestBody, action);
});
}

return;
} catch (err) {
let exception: Exception | null = null;
if (err instanceof Exception) {
exception = err;
} else {
exception = new Exception(
ExceptionType.Request_Failed,
"BAP Request Failed at bapClientTriggerSettler",
500,
err
);
}

logger.error(exception);
}
};


const responseHandler = async(res:any, requestBody:any, action:any) => {
try{
const response = {
data: JSON.stringify(res.data),
status: res.status
};
logger.info(
`Result : Request Successful \nStatus: ${response.status} \nData : ${JSON.stringify(response.data)}`
);
if (
response.status == 200 ||
response.status == 202 ||
response.status == 206
) {
// Network Calls Succeeded.
const additionalCustomAttrsConfig = getConfig().app.telemetry.messageProperties;
const additionalCustomAttrs = customAttributes(requestBody, additionalCustomAttrsConfig);
const additionalCustomAttrs = customAttributes(requestBody, additionalCustomAttrsConfig);
telemetrySDK.onApi({ data: { attributes: { "http.status.code": response.status, ...additionalCustomAttrs } } })(requestBody, response);
return;
}

switch (getConfig().client.type) {
case ClientConfigType.synchronous: {
const message_id = requestBody.context.message_id;
await SyncCache.getInstance().recordError(
message_id,
action as RequestActions,
{
} else {
switch (getConfig().client.type) {
case ClientConfigType.synchronous: {
const message_id = requestBody.context.message_id;
await SyncCache.getInstance().recordError(
message_id,
action as RequestActions,
{
// TODO: change this error code.
code: 651641,
type: BecknErrorType.coreError,
message: "Network Participant Request Failed...",
data: [response]
}
);
break;
}
case ClientConfigType.messageQueue: {
// TODO: Implement message queue.
break;
}
case ClientConfigType.webhook: {
const context = JSON.parse(JSON.stringify(requestBody.context));
await errorCallback(context, {
// TODO: change this error code.
code: 651641,
type: BecknErrorType.coreError,
message: "Network Participant Request Failed...",
data: [response]
}
);
break;
}
case ClientConfigType.messageQueue: {
// TODO: Implement message queue.
break;
}
case ClientConfigType.webhook: {
await errorCallback(context, {
// TODO: change this error code.
code: 651641,
type: BecknErrorType.coreError,
message: "Network Participant Request Failed...",
data: [response]
});
break;
});
break;
}
}
}

return;
} catch (err) {
let exception: Exception | null = null;
if (err instanceof Exception) {
Expand All @@ -203,4 +231,4 @@ export const bapClientTriggerSettler = async (

logger.error(exception);
}
};
};
Loading

0 comments on commit bcaf13a

Please sign in to comment.