From b3d3389dca5e9aed5b02fb6e84c60bf699871870 Mon Sep 17 00:00:00 2001 From: isra el Date: Thu, 17 Oct 2024 09:50:04 +0300 Subject: [PATCH] fix(api): return error message if sms is not sent due to fcm failure --- api/src/gateway/gateway.service.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/api/src/gateway/gateway.service.ts b/api/src/gateway/gateway.service.ts index 040a0ee..0d38cad 100644 --- a/api/src/gateway/gateway.service.ts +++ b/api/src/gateway/gateway.service.ts @@ -185,9 +185,20 @@ export class GatewayService { console.log(response) + if (response.successCount === 0) { + throw new HttpException( + { + success: false, + error: 'Failed to send SMS', + additionalInfo: response, + }, + HttpStatus.BAD_REQUEST, + ) + } + this.deviceModel .findByIdAndUpdate(deviceId, { - $inc: { sentSMSCount: recipients.length }, + $inc: { sentSMSCount: response.successCount }, }) .exec() .catch((e) => {