Skip to content

Commit

Permalink
CHI-2518 Better error handling when sending a message through Modica (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
murilovmachado authored Jan 18, 2024
1 parent a29e5a8 commit f583fe1
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions functions/webhooks/modica/FlexToModica.protected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ import {
FlexToCustomChannel,
} from '../../helpers/customChannels/flexToCustomChannel.private';

class ModicaError extends Error {
status: number;

statusText: string;

data: any;

constructor(status: number, statusText: string, json: any) {
super(json);
this.status = status;
this.statusText = statusText;
this.data = json;
}
}

// This can be a candidate to be an environment variable
const MODICA_SEND_MESSAGE_URL = 'https://api.modicagroup.com/rest/gateway/messages';

Expand Down Expand Up @@ -91,13 +106,10 @@ const sendMessageThroughModica =

if (!result.ok) {
/**
* What should we log as error?
* The fetch's response might include more useful info.
*
* Also, we're not using console.error here so we don't get duplicated
* errors on Twilio.
* Modica returns a json when the request fails.
*/
console.log('>> Could not send message through Modica');
const json = await result.json();
throw new ModicaError(result.status, result.statusText, json);
}
};

Expand Down

0 comments on commit f583fe1

Please sign in to comment.