sendDeleteRequest method

Future sendDeleteRequest({
  1. required String route,
  2. required bool isParams,
  3. Map? body,
  4. String? params,
})

Implementation

Future<dynamic> sendDeleteRequest(
    {required String route,
    required bool isParams,
    Map? body,
    String? params}) async {
  try {
    if (isParams) {
      String subUrl = route;
      Uri uri = Uri.parse(baseApiUrl + subUrl + params!.toLowerCase());
      http.Response response = await client.delete(uri, headers: headers);
      int code = response.statusCode;
      if (code == 401) {
        throw UnauthorizedException();
      } else if (code == 500) {
        throw BadRequestException();
      } else {
        return jsonDecode(response.body);
      }
    } else {
      String subUrl = route;
      Uri uri = Uri.parse(baseApiUrl + subUrl);
      http.Response response =
          await client.delete(uri, body: jsonEncode(body), headers: headers);
      int code = response.statusCode;
      if (code == 401) {
        throw Exception("Unauthorized");
      } else if (code == 500) {
        throw Exception("Server Error");
      } else {
        return jsonDecode(response.body);
      }
    }
  } on SocketException catch (e) {
    debugPrint(e.toString());
    throw ServerException();
  } on FormatException catch (e) {
    debugPrint(e.toString());
    throw FormatInputException();
  } on HttpException catch (e) {
    debugPrint(e.toString());
    throw BadRequestException();
  } catch (e) {
    debugPrint(e.toString());
    throw AnonymousException();
  }
}