Skip to content

Commit 95e6201

Browse files
committed
error message fixed
1 parent ccac6a6 commit 95e6201

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

backend/src/components/canadaPost.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ 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) {
49+
console.log('response.data' + response.data);
50+
if (Array.isArray(response.data) && response.data[0]?.Error) {
5151
const errorObj = response.data[0];
52+
console.log('errorObj' + errorObj);
5253
log.error('Canada Post address object contains an error', {
5354
searchTerm: req?.query?.searchTerm,
5455
errorCode: errorObj.Error,
@@ -66,8 +67,18 @@ async function findAddresses(req, res) {
6667
log.verbose(`Canada Post findAddresses :: Cache miss for search term: '${req?.query?.searchTerm}'. Calling AddressComplete API.`);
6768
return res.status(HttpStatus.OK).json(response.data);
6869
} catch (e) {
69-
log.error(e);
70-
throw new ApiError(HttpStatus.INTERNAL_SERVER_ERROR, { message: 'API Find error' }, e);
70+
log.error('AddressComplete API lookup failed', {
71+
searchTerm: req?.query?.searchTerm,
72+
error: e.message,
73+
statusCode: e.response?.status,
74+
errorData: e.response?.data,
75+
});
76+
77+
return res.status(HttpStatus.BAD_REQUEST).json({
78+
success: false,
79+
message: "We couldn't verify that address. Please check the spelling or enter it manually.",
80+
isError: true,
81+
});
7182
}
7283
}
7384

0 commit comments

Comments
 (0)