trackinfo function

Future<Response> trackinfo(
  1. Dio client,
  2. String id,
  3. String token
)

Implementation

Future<Response> trackinfo(Dio client, String id, String token) async {
  try {
    Response res = await client.post(
      "$webUrl?api_token=$token&api_version=1.0&input=3&method=deezer.pageTrack",
      data: {"sng_id": id},
      options: Options(contentType: "application/json"),
    );
    // md5_origin is null if the login is expired
    // without the md5_origin user can't access the track
    if (res.data['results']['DATA']['MD5_ORIGIN'] == null) {
      throw DeezerException(
        type: DeezerExceptionType.invalidToken,
        message: "Invalid token: Try to refresh the token or add new arl",
      );
    } else {
      return res;
    }
  } catch (e, s) {
    log('Error: $e', stackTrace: s);
    if (e is DioException) {
      throw DeezerException(
        type: DeezerExceptionType.network,
        message: "Network error: ${e.message}",
        error: e,
        stackTrace: s,
      );
    } else if (e is DeezerException) {
      rethrow;
    } else {
      throw DeezerException(
        type: DeezerExceptionType.unknown,
        message: "Unknown error: $e",
        error: e,
        stackTrace: s,
      );
    }
  }
}