File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed
nextstep-backend/src/services Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change 11import axios from 'axios' ;
22
3- export const getCompanyLogo = async ( companyName : string ) : Promise < string | null > => {
3+ export const getCompanyLogo = async ( companyName : string , extensions : string [ ] = [ '.com' , '.co.il' ] ) : Promise < string | null > => {
44 try {
5- const response = await axios . get ( `https://logo.clearbit.com/${ encodeURIComponent ( companyName ) } .com` ) ;
6- return response . status === 200 ? response . config . url ?? null : null ;
5+ for ( const extension of extensions ) {
6+ try {
7+ const response = await axios . get ( `https://logo.clearbit.com/${ encodeURIComponent ( companyName ) } ${ extension } ` ) ;
8+ if ( response . status === 200 ) {
9+ return response . config . url ! ;
10+ }
11+ } catch ( error ) {
12+ // Continue to next extension if this one fails
13+ continue ;
14+ }
15+ }
16+ return null ;
717 } catch ( error ) {
818 if ( error instanceof Error ) {
919 console . error ( `Failed to fetch logo for company: ${ companyName } ` , error . message ) ;
You can’t perform that action at this time.
0 commit comments