server/lib/apis/shop.dart

50 lines
1.2 KiB
Dart

// ignore_for_file: unnecessary_brace_in_string_interps
import 'package:dio/dio.dart';
import 'package:server/apis/auth.dart';
import 'package:server/client.dart';
class Shop {
String lastError = '';
getNews() async {
await auth.setToken();
try {
final response = await api.get('/collections/news/records');
if (response.data != null) {
return response.data;
}
} on DioException catch (e) {
if (e.type == DioExceptionType.connectionError) {
lastError = 'Internet Connection errror';
}
lastError = e.response!.data['message'];
} catch (e) {
print('empty error');
return 'empty errror';
}
}
getCatalog() async {
await auth.setToken();
try {
final response = await api.get('collections/products/records');
if (response.data != null) {
return response.data;
} else {
return Error();
}
} on DioException catch (e) {
if (e.type == DioExceptionType.connectionError) {
lastError = 'Internet Connection errror';
}
lastError = e.response!.data['message'];
} catch (e) {
print('empty error');
return 'empty errror';
}
}
}
final shop = Shop();