File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ) {
You can’t perform that action at this time.
0 commit comments