getWhoAgent method

  1. @override
Future<Response<WhoIsAgentResponse>> getWhoAgent({
  1. required String token,
  2. required WhoAgentRequest request,
})
override

Implementation

@override
Future<Response<WhoIsAgentResponse>> getWhoAgent({
  required String token,
  required WhoAgentRequest request,
}) async {
  return await _whoAgentClient
      .post<Map<String, dynamic>>(
    ApiConstants.whoAgent,
    data: request.toJson(),
    options: Options(
      headers: {
        'Authorization': token,
        'Content-Type': 'application/json',
      },
    ),
  )
      .then((response) {
    return Response<WhoIsAgentResponse>(
      data: WhoIsAgentResponse.fromJson(response.data ?? {}),
      headers: response.headers,
      requestOptions: response.requestOptions,
      statusCode: response.statusCode,
      statusMessage: response.statusMessage,
      extra: response.extra,
    );
  })
      .catchError((error) {
    String errorMessage = 'Failed to get agent information';
    if (error is DioException) {
      errorMessage = error.response?.data?['message'] ??
          error.message ??
          'Unable to fetch agent details';
    }
    _showError(errorMessage);
    throw error;
  });
}