title: Spotify Web API with Axios returns error 500 randomly
body: <p>I have an array of songs, structure is the following, FYI there are around 35 items in the array in the case I'm doing</p>
  <pre><code>songs [
    {
      song_id: '09wkyp6dMAo5JakEj49R0M',
      artist_id: '5EmEZjq8eHEC6qFnT63Lza',
    },
    {
      song_id: '2GaEPiwjVhSMrhX0zC5zJL',
      artist_name: '5EmEZjq8eHEC6qFnT63Lza'
    }
  ]
  </code></pre>
  <p>I'm doing a for loop through each song</p>
  <pre><code>const assignSongsToPlaylists = async () =&gt; {
    for (let s of songs) {
      //getting groupID from my MongoDB
      const { connectedGroupId } = await Artist.findOne({
        artistSpotifyId: s.artist_id,
      })
      //needed the groupID from above in here, to find to which playlist should I put the song in
      const { connectedPlaylistId } = await Group.findOne({
        _id: connectedGroupId,
      })
      //putting the song into a specific playlist
      const response = await axios.post(
        `/playlists/${connectedPlaylistId}/tracks?uris=spotify%3Atrack%3A${s.song_id}`,
      )
    }
  }
  
  const response = await assignSongsToPlaylists()
  </code></pre>
  <p>The issue here is, that sometimes the action is successfull, meaning that all songs from the aforementioned array are successfully added to single or multiple playlists in my Spotify account,   all <code>axios post</code> requests are successfull.</p>
  <p>However, sometimes the <code>axios post</code> fails after couple of songs(it failed after 5 songs, sometimes after 25 songs, tends to fail randomly) and results in the following error:</p>
  <pre><code>[AxiosError: Request failed with status code 500] {
    code: 'ERR_BAD_RESPONSE',
    config: {
      transitional: {
        silentJSONParsing: true,
        forcedJSONParsing: true,
        clarifyTimeoutError: false
      },
      adapter: [Function: httpAdapter],
      transformRequest: [ [Function: transformRequest] ],
      transformResponse: [ [Function: transformResponse] ],
      timeout: 0,
      xsrfCookieName: 'XSRF-TOKEN',
      xsrfHeaderName: 'X-XSRF-TOKEN',
      maxContentLength: -1,
      maxBodyLength: -1,
      env: { FormData: [Function] },
      validateStatus: [Function: validateStatus],
      headers: {
        Accept: 'application/json, text/plain, */*',
        'Content-Type': 'application/json',
        Authorization: 'Bearer BQDRCNSvjVhblc90InW1yFRUql0DDfjvjYTahkyrlvSwLr254eBa2NKv2ci4wUPKc3u9iL5ebDfVijHbyrs0aBnB1yhTRswaC_X9sqrquLFHXLebcwO4JnKRb4vJyFoyEd2950lpTkaKQz1egqubs-ciM4gIq9QzWDCSi7INBKIb6kscJrJrPXrlC_gTp0gyL-VUBNrqoalsPhjmZd9ehwJumbkXNX5v0DWBmSXCcUuflap3G_LCYb_CpT',
        'User-Agent': 'axios/0.27.2'
      },
      baseURL: 'https://api.spotify.com/v1',
      method: 'post',
      url: '/playlists/0nK2ra8DA5ZLB7dFcCgRMw/tracks?uris=spotify%3Atrack%3A0cjYF44Vkl5UK2xYf6KM65',
      data: undefined
    },
    request: &lt;ref *1&gt; ClientRequest {
      _events: [Object: null prototype] {
        abort: [Function (anonymous)],
        aborted: [Function (anonymous)],
        connect: [Function (anonymous)],
        error: [Function (anonymous)],
        socket: [Function (anonymous)],
        timeout: [Function (anonymous)],
        prefinish: [Function: requestOnPrefinish]
      },
      _eventsCount: 7,
      _maxListeners: undefined,
      outputData: [],
      outputSize: 0,
      writable: true,
      destroyed: false,
      _last: true,
      chunkedEncoding: false,
      shouldKeepAlive: false,
      maxRequestsOnConnectionReached: false,
      _defaultKeepAlive: true,
      useChunkedEncodingByDefault: true,
      sendDate: false,
      _removedConnection: false,
      _removedContLen: false,
      _removedTE: false,
      _contentLength: 0,
      _hasBody: true,
      _trailer: '',
      finished: true,
      _headerSent: true,
      _closed: false,
      socket: TLSSocket {
        _tlsOptions: [Object],
        _secureEstablished: true,
        _securePending: false,
        _newSessionPending: false,
        _controlReleased: true,
        secureConnecting: false,
        _SNICallback: null,
        servername: 'api.spotify.com',
        alpnProtocol: false,
        authorized: true,
        authorizationError: null,
        encrypted: true,
        _events: [Object: null prototype],
        _eventsCount: 10,
        connecting: false,
        _hadError: false,
        _parent: null,
        _host: 'api.spotify.com',
        _readableState: [ReadableState],
        _maxListeners: undefined,
        _writableState: [WritableState],
        allowHalfOpen: false,
        _sockname: null,
        _pendingData: null,
        _pendingEncoding: '',
        server: undefined,
        _server: null,
        ssl: [TLSWrap],
        _requestCert: true,
        _rejectUnauthorized: true,
        parser: null,
        _httpMessage: [Circular *1],
        [Symbol(res)]: [TLSWrap],
        [Symbol(verified)]: true,
        [Symbol(pendingSession)]: null,
        [Symbol(async_id_symbol)]: 1494,
        [Symbol(kHandle)]: [TLSWrap],
        [Symbol(kSetNoDelay)]: false,
        [Symbol(lastWriteQueueSize)]: 0,
        [Symbol(timeout)]: null,
        [Symbol(kBuffer)]: null,
        [Symbol(kBufferCb)]: null,
        [Symbol(kBufferGen)]: null,
        [Symbol(kCapture)]: false,
        [Symbol(kBytesRead)]: 0,
        [Symbol(kBytesWritten)]: 0,
        [Symbol(connect-options)]: [Object],
        [Symbol(RequestTimeout)]: undefined
      },
      _header: 'POST /v1/playlists/1nK2ra8Zw5ZLf7dFcMgRMw/tracks?uris=spotify%3Atrack%3A0cjYF44Vkl5UK2xYf6KM65 HTTP/1.1\r\n' +
        'Accept: application/json, text/plain, */*\r\n' +
        'Content-Type: application/json\r\n' +
        'Authorization: Bearer BQDRCNSvjVhblc90InW1yFRUql0DDfjvjYTahkyrlvSwLr254eBa2NKv2ci4wUPKc3u9iL5ebDfVijHbyrs0aBnB1yhTRswaC_X9sqrquLFHXLebcwO4JnKRb4vJyFoyEd2950lpTkaKQz1egqubs-ciM4gIq9QzWDCSi7INBKIb6kscJrJrPXrlC_gTp0gyL-VUBNrqoalsPhjmZd9ehwJumbkXNX5v0DWBmSXCcUuflap3G_LCYb_CpT\r\n' +
        'User-Agent: axios/0.27.2\r\n' +
        'Host: api.spotify.com\r\n' +
        'Connection: close\r\n' +
        'Content-Length: 0\r\n' +
        '\r\n',
      _keepAliveTimeout: 0,
      _onPendingData: [Function: nop],
      agent: Agent {
        _events: [Object: null prototype],
        _eventsCount: 2,
        _maxListeners: undefined,
        defaultPort: 443,
        protocol: 'https:',
        options: [Object: null prototype],
        requests: [Object: null prototype] {},
        sockets: [Object: null prototype],
        freeSockets: [Object: null prototype] {},
        keepAliveMsecs: 1000,
        keepAlive: false,
        maxSockets: Infinity,
        maxFreeSockets: 256,
        scheduling: 'lifo',
        maxTotalSockets: Infinity,
        totalSocketCount: 1,
        maxCachedSessions: 100,
        _sessionCache: [Object],
        [Symbol(kCapture)]: false
      },
      socketPath: undefined,
      method: 'POST',
      maxHeaderSize: undefined,
      insecureHTTPParser: undefined,
      path: '/v1/playlists/1nK2ra8Zd5ZWf7dFcXgRMw/tracks?uris=spotify%3Atrack%3A0cjYF44Vkl5UK2xYf6KM65',
      _ended: true,
      res: IncomingMessage {
        _readableState: [ReadableState],
        _events: [Object: null prototype],
        _eventsCount: 4,
        _maxListeners: undefined,
        socket: [TLSSocket],
        httpVersionMajor: 1,
        httpVersionMinor: 1,
        httpVersion: '1.1',
        complete: true,
        rawHeaders: [Array],
        rawTrailers: [],
        aborted: false,
        upgrade: false,
        url: '',
        method: null,
        statusCode: 500,
        statusMessage: 'Internal Server Error',
        client: [TLSSocket],
        _consuming: false,
        _dumped: false,
        req: [Circular *1],
        responseUrl: 'https://api.spotify.com/v1/playlists/4fK2ra8Zd5WLf72FcMgRMw/tracks?uris=spotify%3Atrack%3A0cjYF44Vkl5UK2xYf6KM65',
        redirects: [],
        [Symbol(kCapture)]: false,
        [Symbol(kHeaders)]: [Object],
        [Symbol(kHeadersCount)]: 34,
        [Symbol(kTrailers)]: null,
        [Symbol(kTrailersCount)]: 0,
        [Symbol(RequestTimeout)]: undefined
      },
      aborted: false,
      timeoutCb: null,
      upgradeOrConnect: false,
      parser: null,
      maxHeadersCount: null,
      reusedSocket: false,
      host: 'api.spotify.com',
      protocol: 'https:',
      _redirectable: Writable {
        _writableState: [WritableState],
        _events: [Object: null prototype],
        _eventsCount: 3,
        _maxListeners: undefined,
        _options: [Object],
        _ended: true,
        _ending: true,
        _redirectCount: 0,
        _redirects: [],
        _requestBodyLength: 0,
        _requestBodyBuffers: [],
        _onNativeResponse: [Function (anonymous)],
        _currentRequest: [Circular *1],
        _currentUrl: 'https://api.spotify.com/v1/playlists/3nK2ra84d5ZLf7GFcMgRMw/tracks?uris=spotify%3Atrack%3A0cjYF44Vkl5UK2xYf6KM65',
        [Symbol(kCapture)]: false
      },
      [Symbol(kCapture)]: false,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype] {
        accept: [Array],
        'content-type': [Array],
        authorization: [Array],
        'user-agent': [Array],
        host: [Array]
      }
    },
    response: {
      status: 500,
      statusText: 'Internal Server Error',
      headers: {
        'content-type': 'application/json; charset=utf-8',
        'cache-control': 'private, max-age=0',
        'x-robots-tag': 'noindex, nofollow',
        'access-control-allow-origin': '*',
        'access-control-allow-headers': 'Accept, App-Platform, Authorization, Content-Type, Origin, Retry-After, Spotify-App-Version, X-Cloud-Trace-Context, client-token, content-access-token',
        'access-control-allow-methods': 'GET, POST, OPTIONS, PUT, DELETE, PATCH',
        'access-control-allow-credentials': 'true',
        'access-control-max-age': '604800',
        'content-length': '73',
        'strict-transport-security': 'max-age=31536000',
        'x-content-type-options': 'nosniff',
        vary: 'Accept-Encoding',
        date: 'Sun, 07 Aug 2022 14:02:48 GMT',
        server: 'envoy',
        via: 'HTTP/2 edgeproxy, 1.1 google',
        'alt-svc': 'h3=&quot;:443&quot;; ma=2592000,h3-29=&quot;:443&quot;; ma=2592000',
        connection: 'close'
      },
      config: {
        transitional: [Object],
        adapter: [Function: httpAdapter],
        transformRequest: [Array],
        transformResponse: [Array],
        timeout: 0,
        xsrfCookieName: 'XSRF-TOKEN',
        xsrfHeaderName: 'X-XSRF-TOKEN',
        maxContentLength: -1,
        maxBodyLength: -1,
        env: [Object],
        validateStatus: [Function: validateStatus],
        headers: [Object],
        baseURL: 'https://api.spotify.com/v1',
        method: 'post',
        url: '/playlists/0nK2ra3Fd5ZLf7GFcMgRMw/tracks?uris=spotify%3Atrack%3A0cjYF44Vkl5UK2xYf6KM65',
        data: undefined
      },
      request: &lt;ref *1&gt; ClientRequest {
        _events: [Object: null prototype],
        _eventsCount: 7,
        _maxListeners: undefined,
        outputData: [],
        outputSize: 0,
        writable: true,
        destroyed: false,
        _last: true,
        chunkedEncoding: false,
        shouldKeepAlive: false,
        maxRequestsOnConnectionReached: false,
        _defaultKeepAlive: true,
        useChunkedEncodingByDefault: true,
        sendDate: false,
        _removedConnection: false,
        _removedContLen: false,
        _removedTE: false,
        _contentLength: 0,
        _hasBody: true,
        _trailer: '',
        finished: true,
        _headerSent: true,
        _closed: false,
        socket: [TLSSocket],
        _header: 'POST /v1/playlists/0DF2ra1Zd5ZGG7dFcMgRMw/tracks?uris=spotify%3Atrack%3A0cjYF44Vkl5UK2xYf6KM65 HTTP/1.1\r\n' +
          'Accept: application/json, text/plain, */*\r\n' +
          'Content-Type: application/json\r\n' +
          'Authorization: Bearer BQDRCNSvjVhblc90InW1yFRUql0DDfjvjYTahkyrlvSwLr254eBa2NKv2ci4wUPKc3u9iL5ebDfVijHbyrs0aBnB1yhTRswaC_X9sqrquLFHXLebcwO4JnKRb4vJyFoyEd2950lpTkaKQz1egqubs-ciM4gIq9QzWDCSi7INBKIb6kscJrJrPXrlC_gTp0gyL-VUBNrqoalsPhjmZd9ehwJumbkXNX5v0DWBmSXCcUuflap3G_LCYb_CpT\r\n' +
          'User-Agent: axios/0.27.2\r\n' +
          'Host: api.spotify.com\r\n' +
          'Connection: close\r\n' +
          'Content-Length: 0\r\n' +
          '\r\n',
        _keepAliveTimeout: 0,
        _onPendingData: [Function: nop],
        agent: [Agent],
        socketPath: undefined,
        method: 'POST',
        maxHeaderSize: undefined,
        insecureHTTPParser: undefined,
        path: '/v1/playlists/0nK2rh45d5hLf7dFcMgRMw/tracks?uris=spotify%3Atrack%3A0cjYF44Vkl5UK2xYf6KM65',
        _ended: true,
        res: [IncomingMessage],
        aborted: false,
        timeoutCb: null,
        upgradeOrConnect: false,
        parser: null,
        maxHeadersCount: null,
        reusedSocket: false,
        host: 'api.spotify.com',
        protocol: 'https:',
        _redirectable: [Writable],
        [Symbol(kCapture)]: false,
        [Symbol(kNeedDrain)]: false,
        [Symbol(corked)]: 0,
        [Symbol(kOutHeaders)]: [Object: null prototype]
      },
      data: { error: [Object] }
    }
  }
  </code></pre>
  <p>Any idea what could cause this behavior?</p>