delete method
Implementation
Future<ApiServiceResponse> delete({
required String endpoint,
required Object data,
Map<String, dynamic>? headers,
bool? followRedirects,
CancelToken? cancelToken,
}) async {
LoggerService.logInfo('Endpoint: $endpoint');
LoggerService.logInfo('Input: $data');
LoggerService.logInfo('Headers: $headers');
try {
final response = await _dio.delete<dynamic>(
endpoint,
data: data,
options: Options(
headers: headers,
followRedirects: followRedirects ?? true,
),
cancelToken: cancelToken,
);
LoggerService.logInfo(
'Status code $endpoint: ${response.statusCode}',
);
if (response.statusCode == 200) {
LoggerService.logInfo(
'Response: ${response.data}',
);
return SuccessResponse(
data: response.data,
header: response.headers,
isRedirect: response.isRedirect,
);
}
LoggerService.logError(
'Status not 200 $endpoint: ${response.data}',
);
return FailureResponse(
data: response.data,
header: response.headers,
isRedirect: response.isRedirect,
);
} on DioException catch (err) {
LoggerService.logError(
'Error $endpoint: $err',
);
return FailureResponse(data: 'DioException');
} on FormatException {
LoggerService.logError('Invalid Format: FormatException');
return FailureResponse(data: 'Invalid Format');
} catch (e) {
LoggerService.logError('Error $endpoint: $e');
return FailureResponse(data: 'Invalid Error');
}
}