Skip to content

Commit ccac6a6

Browse files
committed
Now blacklist IP addresses throws appropriate message .
1 parent bbd4748 commit ccac6a6

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

backend/src/components/canadaPost.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,23 @@ async function findAddresses(req, res) {
4646
'Content-Type': 'application/json',
4747
};
4848
const response = await axios.get(url, headers);
49+
50+
if (response.data[0]?.Error) {
51+
const errorObj = response.data[0];
52+
log.error('Canada Post address object contains an error', {
53+
searchTerm: req?.query?.searchTerm,
54+
errorCode: errorObj.Error,
55+
description: errorObj.Description,
56+
cause: errorObj.Cause,
57+
});
58+
throw new Error(`Canada Post error: ${errorObj.Description}`);
59+
}
60+
4961
if (req?.query?.searchTerm && Redis.isReady) {
5062
Redis.client.json.set(REDIS_MAP, `$.${Redis.encodeKey(req?.query?.searchTerm)}`, response.data);
5163
Redis.client.expire(REDIS_MAP, ...REDIS_EXPIRE_ARGS);
5264
}
65+
5366
log.verbose(`Canada Post findAddresses :: Cache miss for search term: '${req?.query?.searchTerm}'. Calling AddressComplete API.`);
5467
return res.status(HttpStatus.OK).json(response.data);
5568
} catch (e) {

0 commit comments

Comments
 (0)