Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Last Fm API 504 on Upload #7

Open
kalebakeits opened this issue Jan 7, 2025 · 0 comments
Open

Last Fm API 504 on Upload #7

kalebakeits opened this issue Jan 7, 2025 · 0 comments

Comments

@kalebakeits
Copy link

I am experiencing a recurring issue when uploading a batch of tracks to the Last.fm API for scrobbling. Whenever I upload multiple tracks in a batch, I get a 504 Gateway Timeout error for the entire batch. Upon further investigation, I found that the issue is caused by specific tracks in the batch, and if these problematic tracks are excluded, the upload proceeds successfully.

Steps to Reproduce:

  1. Send a batch of tracks via the scrobbleTracks(tracklist) method in the app.
  2. The request will fail with a 504 Gateway Timeout error.
  3. Upon investigating the failed request in the dev tools, it turns out that only certain tracks in the batch cause the error.
  4. I identified the problematic tracks by modifying the function to send individual requests for each track, allowing me to identify which tracks were problematic.
  5. Once the problematic tracks were unticked from the upload list, the individual requests succeeded.

Expected Behavior:

The scrobbling function should be able to gracefully handle failed uploads due to specific tracks. The rest of the tracks should still be processed, and only the problematic tracks should be skipped. Additionally, users should be informed about the failed tracks and the issue should be reported accordingly without automatically deleting them from the list.

Proposed Solution:

To handle this more gracefully, I suggest the following:

  1. Send a request per track instead of batching all the tracks into one request.

  2. For each track:

    • If the request succeeds, continue processing.
    • If the request fails (e.g., due to a 504 error), skip the problematic track and log the failure for the user. The track should remain in the list, and the user can be informed about which tracks failed.
  3. Implement a user notification that indicates which tracks failed and allow the user to reattempt uploading them if necessary.

  4. Avoid deleting failed tracks automatically to allow the user to review and fix any issues before trying again.

Current Code Snippet:

export async function scrobbleTracks(tracklist) {
  console.log('tracklist', tracklist);

  try {
    for (let i = 0; i < tracklist.length; i++) {
      const track = tracklist[i];

      try {
        const response = await axios.post(
          `${serverUrl}/scrobble`,
          { tracklist: [track], sessionKey: preferences.lastFm.sessionKey },
          {
            headers: {
              Authorization: `Bearer ${preferences.lastFm.sessionKey}`,
            },
          }
        );

        if (!response.data.success) {
          // Optionally notify user about failed track
        }
      } catch (error) {
        console.error(`Error scrobbling track ${track.name}:`, error.message);
        // Optionally notify user about failed track
      }
    }

    return { status: true, message: '' };
  } catch (error) {
    console.error('Error:', error.message);
    return { status: false, message: 'Failed to scrobble Tracks' };
  }
}

Additional Information:

  • The issue appears to be specific to certain tracks, and not all tracks in the batch cause failures.
  • The 504 error only occurs when multiple tracks are sent together; individual requests succeed.
  • I’ve also confirmed that the tracks causing the issue are valid and correctly formatted.

Possible Enhancements/Requests:

  • A more robust error handling mechanism that can identify and skip problematic tracks.
  • A UI notification system to alert the user which tracks have failed.
  • A method to retry uploading failed tracks automatically or allow users to fix and re-upload them.
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

No branches or pull requests

1 participant