Skip to content

Commit

Permalink
Merge pull request #903 from serbinadrian/master
Browse files Browse the repository at this point in the history
[SPT-328] Added multiple GRPC request handler
  • Loading branch information
serbinadrian authored Apr 16, 2024
2 parents 2f081c4 + bb37975 commit cfb1cbb
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/utility/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,22 +272,37 @@ export const createServiceClient = (
options
);

const finishServiceInteraction = () => {
if(serviceRequestCompleteHandler) {
serviceRequestCompleteHandler();
return;
}
}

const onEnd = props => (...args) => {
try {
const { status, statusMessage } = args[0];
if (status !== 0) {
serviceRequestErrorHandler(statusMessage);
return;
}
props.onEnd(...args);

if(props.onEnd) {
props.onEnd(...args);
}

if (props.preventCloseServiceOnEnd) {
return;
}

if (serviceRequestCompleteHandler) {
serviceRequestCompleteHandler();
}
} catch (error) {
serviceRequestErrorHandler(error);
}
};

const requestStartHandler = () => {
if (serviceRequestStartHandler) {
serviceRequestStartHandler();
Expand All @@ -303,6 +318,9 @@ export const createServiceClient = (
requestStartHandler();
serviceClient.unary(methodDescriptor, { ...props, onEnd: onEnd(props) });
},
stopService() {
finishServiceInteraction();
},
getMethodNames,
};
} catch (error) {
Expand Down

0 comments on commit cfb1cbb

Please sign in to comment.