mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-11-27 14:44:56 +00:00
revert back http
This commit is contained in:
@ -1,7 +1,4 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_web/services/api/http_interceptor.dart';
|
||||
import 'package:syncrow_web/services/locator.dart';
|
||||
import 'package:syncrow_web/utils/constants/api_const.dart';
|
||||
@ -35,56 +32,32 @@ class HTTPService {
|
||||
bool showServerMessage = true,
|
||||
}) async {
|
||||
try {
|
||||
// Log the request path and query parameters
|
||||
debugPrint('GET Request: $path');
|
||||
if (queryParameters != null) {
|
||||
debugPrint('Query Parameters: $queryParameters');
|
||||
}
|
||||
|
||||
// Perform the HTTP GET request
|
||||
final response = await client.get(
|
||||
path,
|
||||
queryParameters: queryParameters,
|
||||
);
|
||||
|
||||
// Log the raw response data
|
||||
debugPrint('Response Data: ${response.data}');
|
||||
|
||||
// Process the response using the expected model function
|
||||
final result = expectedResponseModel(response.data);
|
||||
|
||||
return result;
|
||||
return expectedResponseModel(response.data);
|
||||
} catch (error) {
|
||||
// Log the error details
|
||||
debugPrint('Error in GET Request: $error');
|
||||
rethrow; // Re-throw the error to propagate it further
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<T> post<T>({
|
||||
required String path,
|
||||
Map<String, dynamic>? queryParameters,
|
||||
Options? options,
|
||||
dynamic body,
|
||||
bool showServerMessage = true,
|
||||
required T Function(dynamic) expectedResponseModel,
|
||||
}) async {
|
||||
Future<T> post<T>(
|
||||
{required String path,
|
||||
Map<String, dynamic>? queryParameters,
|
||||
Options? options,
|
||||
dynamic body,
|
||||
bool showServerMessage = true,
|
||||
required T Function(dynamic) expectedResponseModel}) async {
|
||||
try {
|
||||
final bodyString = body is Map || body is List
|
||||
? jsonEncode(body)
|
||||
: body?.toString() ?? 'null';
|
||||
|
||||
print("POST Request: $path, Body: $bodyString, Query: $queryParameters");
|
||||
final response = await client.post(
|
||||
path,
|
||||
data: body,
|
||||
queryParameters: queryParameters,
|
||||
options: options,
|
||||
);
|
||||
print("POST Response: ${response.data.toString()}");
|
||||
return expectedResponseModel(response.data);
|
||||
} catch (error) {
|
||||
print("POST Error: $error");
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user