Skip to content

Commit

Permalink
Merge pull request #9 from choxx/6-be-uci-odk-adapter-shift-to-cdac-s…
Browse files Browse the repository at this point in the history
…ervice-instead-of-uci

CdacService: optimized logic to extract messageId; handled error case
  • Loading branch information
choxx authored Jan 25, 2023
2 parents 4893b37 + 7eca4a9 commit 5570b1e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/sms-adapter/cdac/cdac.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,18 @@ export class CdacService implements SmsAdapterInterface {
const url = `${
this.cdacServiceUrl
}/api/send_single_unicode_sms?${params.toString()}`;
console.log(url);
return await lastValueFrom(
this.httpService.get(url).pipe(
map((response: any) => {
let messageId = response.data.toString();
messageId = messageId.trim('402,MsgID = ');
messageId = messageId.trim('hpgovt-hpssa');
const statusCode = messageId.substring(0, 3) || '0';
if (statusCode != '402') {
throw new HttpException(
{ error: `CDAC Error: ${messageId}`, data: {} },
statusCode,
); // or else throw exception
}
messageId = messageId.slice(12, -1);
const resp = {
timestamp: new Date(),
status: 200,
Expand All @@ -55,6 +60,7 @@ export class CdacService implements SmsAdapterInterface {
return resp;
}),
catchError((e) => {
console.log(e.response);
this.logger.error(
`Processing registerSms() FAILURE: ${JSON.stringify(
e.response.data,
Expand Down

0 comments on commit 5570b1e

Please sign in to comment.