Skip to content

Commit 7980ff7

Browse files
committed
fix: Validate Unsplash Access Key in getUnsplashImage (#239)
* Return an empty string and log an error if ACCESS_KEY is missing * Prevents potential runtime errors when the environment variable isn't set
1 parent 094738e commit 7980ff7

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/api/services/quotesService.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ module.exports = {
7171

7272
async function getUnsplashImage(query) {
7373
const accessKey = process.env.UNSPLASH_ACCESS_KEY;
74+
if (!accessKey) {
75+
console.error('Unsplash access key not configured');
76+
return '';
77+
}
78+
7479
const unsplashUrl = `https://api.unsplash.com/photos/random?query=${encodeURIComponent(query)}&client_id=${accessKey}`;
7580

7681
try {

0 commit comments

Comments
 (0)