mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 09:45:22 +00:00
Added Error handling
This commit is contained in:
@ -2,23 +2,24 @@ import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_app/services/api/api_links_endpoints.dart';
|
||||
import 'package:syncrow_app/services/api/http_interceptor.dart';
|
||||
import 'package:syncrow_app/services/api/network_exception.dart';
|
||||
import 'package:syncrow_app/services/locator.dart';
|
||||
|
||||
class HTTPService {
|
||||
late Dio client = serviceLocator.get<Dio>();
|
||||
final Dio client = serviceLocator.get<Dio>();
|
||||
|
||||
// final navigatorKey = GlobalKey<NavigatorState>();
|
||||
|
||||
String certificateString = "";
|
||||
|
||||
Dio setupDioClient() {
|
||||
client = Dio(
|
||||
static Dio setupDioClient() {
|
||||
Dio client = Dio(
|
||||
BaseOptions(
|
||||
baseUrl: ApiEndpoints.baseUrl,
|
||||
receiveDataWhenStatusError: true,
|
||||
followRedirects: false,
|
||||
connectTimeout: const Duration(minutes: 1),
|
||||
receiveTimeout: const Duration(minutes: 1),
|
||||
connectTimeout: const Duration(seconds: 60),
|
||||
receiveTimeout: const Duration(seconds: 60),
|
||||
),
|
||||
);
|
||||
|
||||
@ -53,16 +54,17 @@ class HTTPService {
|
||||
bool showServerMessage = true,
|
||||
required T Function(dynamic) expectedResponseModel}) async {
|
||||
try {
|
||||
final response = await client.post(path,
|
||||
data: body, queryParameters: queryParameters, options: options);
|
||||
print("post response is $response");
|
||||
final response = await client.post(
|
||||
path,
|
||||
data: body,
|
||||
queryParameters: queryParameters,
|
||||
options: options,
|
||||
);
|
||||
debugPrint("status code is ${response.statusCode}");
|
||||
debugPrint("response data is ${response.data}");
|
||||
return expectedResponseModel(response.data);
|
||||
} catch (error) {
|
||||
debugPrint("******* Error ********");
|
||||
debugPrint(error.toString());
|
||||
rethrow;
|
||||
} on DioException catch (error) {
|
||||
throw ServerFailure.fromDioError(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user