From 7eca4a951b12a860c16299ea8528da3620c9d8ba Mon Sep 17 00:00:00 2001 From: Abhishek Mishra Date: Wed, 25 Jan 2023 13:18:41 +0530 Subject: [PATCH] CdacService: optimized logic to extract messageId; handled error case from CDAC --- src/sms-adapter/cdac/cdac.service.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/sms-adapter/cdac/cdac.service.ts b/src/sms-adapter/cdac/cdac.service.ts index 7668e2b..6c8ca2e 100644 --- a/src/sms-adapter/cdac/cdac.service.ts +++ b/src/sms-adapter/cdac/cdac.service.ts @@ -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, @@ -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,