Skip to content

fix(media): don't 500 when the Unsplash/Giphy key is set to null#144

Open
dantaspaulo wants to merge 1 commit into
trypostit:mainfrom
dantaspaulo:fix/media-services-null-key
Open

fix(media): don't 500 when the Unsplash/Giphy key is set to null#144
dantaspaulo wants to merge 1 commit into
trypostit:mainfrom
dantaspaulo:fix/media-services-null-key

Conversation

@dantaspaulo

Copy link
Copy Markdown

Problem

config('services.unsplash.access_key', '') only falls back to '' when the
key is absent. If the env var is present but empty, config() returns
null, and assigning null to the string property throws a TypeError in the
constructor — taking the whole request down with a 500 during media search.
GiphyService has the same issue with services.giphy.api_key.

Fix

Cast to (string) so a null/empty key degrades gracefully to ''. Both services
already return an empty result set when the key is empty (if (empty(...))), so
this restores that intended behavior instead of throwing.

Tests

MediaSearchKeyFallbackTest — constructing each service with a null key and
calling search() returns an empty result set without throwing.

`config('services.unsplash.access_key', '')` only falls back to '' when the key
is *absent* — if the env var is present but empty, config returns null, and
assigning null to the `string` property throws a TypeError, taking the whole
request down with a 500 during media search.

Cast to `(string)` so a null/empty key degrades gracefully to '' and the service
returns an empty result set (as it already does for a missing key) instead of
throwing.

Covered by a regression test for both services.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant