try catch on endpoint call. stackoverflow code example
Example: data at transit encrypting nodejs stack overflow
var crypto = require('crypto');
var assert = require('assert');
var algorithm = 'aes256';
var key = 'password';
var text = 'I love kittens';
var cipher = crypto.createCipher(algorithm, key);
var encrypted = cipher.update(text, 'utf8', 'hex') + cipher.final('hex');
var decipher = crypto.createDecipher(algorithm, key);
var decrypted = decipher.update(encrypted, 'hex', 'utf8') + decipher.final('utf8');
assert.equal(decrypted, text);