updateEnginEquipe static method

Future<UpdateVoieResponse> updateEnginEquipe(
  1. EnginEquipe enginEquipe
)

Implementation

static Future<UpdateVoieResponse> updateEnginEquipe(
  EnginEquipe enginEquipe,
) async {
  TokenService tokenService = TokenService();
  String? token = await tokenService.getToken();

  var json = enginEquipe.toJson();

  try {
    final response = await Dio().patch(
      '$hostUrl/engin_equipes',
      data: jsonEncode(json),
      options: Options(
        headers: {
          'Authorization': 'Bearer $token',
          'Content-Type': 'application/json',
        },
      ),
    );

    print(response.data);

    final supportedStatusCode = [403, 200, 400];
    if (supportedStatusCode.contains(response.statusCode)) {
      var data = response.data;
      UpdateVoieResponse assignEngin = UpdateVoieResponse.fromJson(data);
      return assignEngin;
    } else {
      throw Exception('Unexpected status code: ${response.statusCode}');
    }
  } on DioException catch (e) {
    print('Dio error!');
    if (e.response != null) {
      print('Dio error response: ${e.response}');
      print('Dio error response data: ${e.response?.data}');
      print('Dio error response headers: ${e.response?.headers}');
      print('Dio error response status code: ${e.response?.statusCode}');
    } else {
      print('Error sending request: $e');
    }
    throw Exception('Failed to load');
  } catch (e) {
    print('Other error: $e');
    throw Exception('Failed to load');
  }
}