getCurrentCustomer method

Future<Customer> getCurrentCustomer()

Get current customer information

Implementation

Future<Customer> getCurrentCustomer() async {
  try {
    final response = await _client.authenticatedRequest<Map<String, dynamic>>(
      '/rest/V1/customers/me',
    );

    if (response.statusCode == 200) {
      return Customer.fromJson(response.data!);
    } else {
      throw Exception(
        'Failed to get customer info: ${response.statusMessage}',
      );
    }
  } on DioException catch (e) {
    if (e.response?.statusCode == 401) {
      throw Exception('User not authenticated');
    }
    throw Exception('Failed to get customer info: ${e.message}');
  } catch (e) {
    throw Exception('Failed to get customer info: $e');
  }
}