MusicKit MusicCatalogResourceRequest for artists with top-songs returns 504 in non-json format

I'm making a request to get 10 artists with their top songs at once, but for some artists it will always fail with a 504. The response is also in HTML which leads to a decoding error. This is my code

var request = MusicCatalogResourceRequest<Artist>(matching: \.id, memberOf: ids)
request.properties = properties
let response = try await request.response()

where ids is MusicItemId. Below I have an input which will always fail 100% of the time, even when retried.

10 elements
 - 0 : "51639"
 - 1 : "331584"
 - 2 : "120199"
 - 3 : "45058"
 - 4 : "284786497"
 - 5 : "44984"
 - 6 : "37299"
 - 7 : "518462"
 - 8 : "39525"
 - 9 : "73568"

Example response:

[DataRequesting] Failed to parse body of response with status code Unknown (504): 
<!DOCTYPE html>
<html lang="en">
<head>
  <style>
    body {
      font-family: "Helvetica Neue", "HelveticaNeue", Helvetica, Arial, sans-serif;
      font-size: 15px;
      font-weight: 200;
      line-height: 20px;
      color: #4c4c4c;
      text-align: center;
    }

    .section {
      margin-top: 50px;
    }
  </style>
</head>
<body>
<div class="section">
  <h1>&#63743;</h1>

  <h3>Gateway Timeout</h3>
  <p>Correlation Key: WFRI6Q5HXAUJYXGNRKQ6YTBYIM</p>
</div>
</body>
</html>

I have also tried batching these into 2 requests of 5 artists instead of 1 request of 10 artists which still fails. However, I do have sets of 10 artists that work fine. Anyone know why?

Replies

I started getting this error recently as well, while making a request to get multiple catalog songs filtered by ISRC (I queried for 25 different codes in a single request, the limit as indicated in the docs).

I guess that depending on the amount of data returned by the ISRC lookup, the server times out? and fails with the Gateway Timeout error.

Here are the ISRC codes I used, in case anyone wants to try to reproduce it:

isrcs = ["USUM71805289",
 "GBAHS1700199",
 "USCA21203108",
 "GBAAA1200728",
 "GBAHS1600462",
 "USRC11600201",
 "USUM71409723",
 "GBAYE0800265",
 "USAT21001985",
 "GBUM71807386",
 "GBARL1600460",
 "CAB391100615",
 "SEUM71401533",
 "GBHMU1500070",
 "USWB10002407",
 "USVR19600010",
 "USUM71800463",
 "USUM71703825",
 "USUM71311296",
 "USUM71211793",
 "USSM11703300",
 "GB28K1100030",
 "GB28K1700019",
 "USCM51300762",
 "USWB10300474"]

This is the amount of nodes each ISRC returned:

{"USUM71805289"=>7,
 "USCA21203108"=>44,
 "GBAHS1700199"=>7,
 "GBUM71807386"=>72,
 "GBAHS1600462"=>33,
 "USAT21001985"=>101,
 "USRC11600201"=>4,
 "GBAYE0800265"=>88,
 "GBAAA1200728"=>28,
 "USUM71409723"=>12,
 "GBARL1600460"=>2,
 "USUM71703825"=>129,
 "USUM71311296"=>72,
 "USUM71800463"=>87,
 "USUM71211793"=>16,
 "USWB10002407"=>41,
 "CAB391100615"=>4,
 "GBHMU1500070"=>4,
 "USVR19600010"=>18,
 "SEUM71401533"=>76,
 "USSM11703300"=>1,
 "GB28K1100030"=>4,
 "GB28K1700019"=>1,
 "USWB10300474"=>17}
Post not yet marked as solved Up vote reply of zrod Down vote reply of zrod

I'm seeing this consistently. 3 failed requests in a row before the 4th actually loads.

This is now happening consistently when trying to request with the includes=albums param.

Apple, please, address our concerns about the instability with your API!