Skip to content

Commit 9681ffe

Browse files
authored
Merge pull request #29 from NextStepFinalProject/NXD-28
NXD 28 - Support logos of Israeli companies
2 parents 3e0fc50 + 580400c commit 9681ffe

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

nextstep-backend/src/services/company_logo_service.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
import 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);

0 commit comments

Comments
 (0)