Skip to content

Fix album token refresh handling and stabilize album lyrics flow#1

Open
spacegrey23 wants to merge 1 commit intomainfrom
codex/run-project-locally-on-windows
Open

Fix album token refresh handling and stabilize album lyrics flow#1
spacegrey23 wants to merge 1 commit intomainfrom
codex/run-project-locally-on-windows

Conversation

@spacegrey23
Copy link
Owner

Motivation

  1. Ensure album fetching does not fail with missing or expired Spotify access tokens by validating and refreshing the token before API calls.
  2. Provide a clear error response when token refresh fails to avoid ambiguous failures.
  3. Support fetching lyrics for every track in an album and render per-track lyrics in the client when given an album link.

Description

  1. Validate and refresh currentAccessToken in backend/api/spotify/getAlbumTracks.mjs and return a structured 500 response when the token remains missing.
  2. Add backend/api/getAlbumLyrics.mjs which iterates album tracks and attempts to collect lyrics via getLyricsBySignature, getLyricsByQuery, and getLyricsFromSpotify.
  3. Register GET /getAlbumData in backend/api/routes/routes.mjs and add album detection to client/src/features/lyrics/useLyrics.js and client/src/hooks/useLyrics.js to route requests to the correct endpoint.
  4. Update client/src/App.jsx to detect album responses and render a list of per-track LyricsCard components, and add backend/test/spotify.test.mjs for parseAlbumId.

Testing

  1. Ran unit tests with node --test backend/test/spotify.test.mjs.
  2. All tests passed: 3 passed, 0 failed.
  3. No end-to-end or integration tests were run; album endpoint behavior requires valid Spotify credentials for manual verification.
  4. The added test verifies parseAlbumId for open.spotify.com and spotify:album: formats and an invalid URL case.

Codex Task

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4e2fbcacfd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +98 to +101
return res.status(404).send(
{
...albumData || null,
status: 404,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid spreading null in album error handler

If an exception occurs before albumData is assigned (e.g., a Spotify API/network error in getAlbumTracks), the catch falls through to the 404 response and spreads albumData || null. Spreading null/undefined throws a TypeError, so the error handler itself fails and the request ends up as an unhandled 500 instead of a clean error response. This path is reachable whenever the try block throws before albumData is set; consider guarding with albumData ? { ...albumData } : {} or similar.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant