getPlayerById method

Future<Player> getPlayerById(
  1. int playerId
)

Requests Player object from server.

Requires player identifier playerId. Returns player object Player in case of success Throws DioError in case of network connection problems or ErrorResponse in case of parsable error

Implementation

Future<Player> getPlayerById(int playerId) async {
  try {
    final Response<String> response = await _dio.get('/players/$playerId');
    return Player.fromRawJson(response.data!);
  } on DioError catch (e) {
    try {
      throw ErrorResponse.fromRawJson(e.response?.data);
    } on TypeError catch (_) {
      throw e;
    }
  }
}