Skip to content

Commit

Permalink
CdacService: optimized logic to extract messageId; handled error case…
Browse files Browse the repository at this point in the history
… from CDAC
  • Loading branch information
choxx committed Jan 25, 2023
1 parent 488ccb4 commit 7eca4a9
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 7eca4a9

Please sign in to comment.