patch method

  1. @override
Future<Response> patch(
  1. String url, {
  2. String? token,
  3. dynamic data,
  4. Map? headers,
  5. String contentType = 'application/json',
  6. int msTimeout = 10000,
})
override

HTTP PATCH

Implementation

@override
Future<Response> patch(
  String url, {
  String? token,
  dynamic data,
  Map? headers,
  String contentType = 'application/json',
  int msTimeout = 10000,
}) async {
  Map<String, dynamic> _headers = Map<String, dynamic>();

  if (headers != null) {
    headers.forEach((k, v) => _headers[k] = v);
  }

  if (token != null) _headers['Authorization'] = 'Bearer $token';

  _headers['Content-Type'] = contentType;

  _dio.options.connectTimeout = msTimeout;
  _dio.options.receiveTimeout = msTimeout;

  try {
    final _response = await _dio.patch(
      url,
      data: data,
      options: Options(headers: _headers),
    );

    return _returnResponse(_response);
  } on DioError catch (e) {
    if (e.type == DioErrorType.connectTimeout) {
      throw TimeoutException(e.error);
    } else if (e.type == DioErrorType.other) {
      throw FetchDataException(e.error);
    } else if (e.type == DioErrorType.response) {
      return _returnResponse(e.response);
    } else {
      throw FetchDataException(e.error);
    }
  }
}