sakibguy / worked-issues

arget medi a[rpescriptionmedicie] &ssets[dr] (reeeverse._ax:p)
2 stars 0 forks source link

[ORG] SG-MYALICE: Unhandled Exception: type 'SendDataSource' is not a subtype of type 'Map<String, dynamic>' #112

Closed sakibguy closed 1 year ago

sakibguy commented 1 year ago

PROB

Past day worked fine no exception logged. Today showing SendDataSource parsing exception.

I/flutter (14212): [---ok---] addToChatResponse(): 1 Instance of 'SendDataSource'
E/flutter (14212): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: type 'SendDataSource' is not a subtype of type 'Map<String, dynamic>'
E/flutter (14212): #0      ChatTextingController.addToChatResponse (package:myalice/controllers/viewController/chatTextingViewController.dart:227:55)
E/flutter (14212): #1      ChatTextingController.sendConvText.<anonymous closure> (package:myalice/controllers/viewController/chatTextingViewController.dart:190:11)
E/flutter (14212): <asynchronous suspension>
E/flutter (14212): #2      ChatTextingController.sendConvText (package:myalice/controllers/viewController/chatTextingViewController.dart:185:7)
E/flutter (14212): <asynchronous suspension>
E/flutter (14212): 

Pusher response (when sent text) and contains _id:null

I/flutter (14212): [---ok---] sendChats: 2 {success: true, dataSource: {_id: null, type: message, source: admin, platform_type: facebook_messenger, platform_id: 1361, customer_id: 1043, project_id: 375, data: {type: text, data: {text: b3}}, conversation_id: m_iUuuVitsngrL4oRDvz7V3k6MoMJwaz_uVqGmpI3rBU_Pe_4zwKGNL4mH2LKJM1S_OLTSzBvNu-k5Y9w47sdu2g, timestamp: 1671283144708, admin_id: 256, admin_info: {id: 256, email: masuma+1@myalice.ai, avatar: https://s3-ap-southeast-1.amazonaws.com/stage-alice-v3/misc/7f2bdade109811ecabd40242c0a82005.jpeg, full_name: Masuma Imu}, success: null, pusher_key: 98d0990d74984ab2be8a047f62cd43c9}}

SNaP

Screenshot (615) Screenshot (616)

sakibguy commented 1 year ago

SendData Parser/Model

import 'data_source.dart';

class SendData {
  bool? success;
  SendDataSource? dataSource;

  SendData({this.success, this.dataSource});

  factory SendData.fromJson(Map<String, dynamic> json) => SendData(
        success: json['success'] as bool?,
        dataSource: json['dataSource'] == null
            ? null
            : SendDataSource.fromJson(
                json['dataSource'] as Map<String, dynamic>),
      );

  Map<String, dynamic> toJson() => {
        'success': success,
        'dataSource': dataSource?.toJson(),
      };
}

SendDataSource Parser/Model

import 'package:myalice/models/responseModels/sendChats/data.dart';

import 'admin_info.dart';

class SendDataSource {
  dynamic id;
  String? type;
  String? source;
  String? platformType;
  int? platformId;
  int? customerId;
  int? projectId;
  Data? data;
  String? conversationId;
  int? timestamp;
  int? adminId;
  AdminInfo? adminInfo;
  dynamic success;
  String? pusherKey;

  SendDataSource({
    this.id,
    this.type,
    this.source,
    this.platformType,
    this.platformId,
    this.customerId,
    this.projectId,
    this.data,
    this.conversationId,
    this.timestamp,
    this.adminId,
    this.adminInfo,
    this.success,
    this.pusherKey,
  });

  factory SendDataSource.fromJson(Map<String, dynamic> json) => SendDataSource(
        id: json['_id'],
        type: json['type'] as String?,
        source: json['source'] as String?,
        platformType: json['platform_type'] as String?,
        platformId: json['platform_id'] as int?,
        customerId: json['customer_id'] as int?,
        projectId: json['project_id'] as int?,
        data: json['data'] == null
            ? null
            : Data.fromJson(json['data'] as Map<String, dynamic>),
        conversationId: json['conversation_id'] as String?,
        timestamp: json['timestamp'] as int?,
        adminId: json['admin_id'] as int?,
        adminInfo: json['admin_info'] == null
            ? null
            : AdminInfo.fromJson(json['admin_info'] as Map<String, dynamic>),
        success: json['success'],
        pusherKey: json['pusher_key'] as String?,
      );

  Map<String, dynamic> toJson() => {
        '_id': id,
        'type': type,
        'source': source,
        'platform_type': platformType,
        'platform_id': platformId,
        'customer_id': customerId,
        'project_id': projectId,
        'data': data?.toJson(),
        'conversation_id': conversationId,
        'timestamp': timestamp,
        'admin_id': adminId,
        'admin_info': adminInfo?.toJson(),
        'success': success,
        'pusher_key': pusherKey,
      };
}
sakibguy commented 1 year ago

Potential Reason

As _id: null might lead parse failed to SendDataSource. But couldn't be as defined dynamic (null value acceptable too) dynamic id;

{success: true, dataSource: {_id: null, type: message, source: admin, platform_type: facebook_messenger, platform_id: 1361, customer_id: 1043, project_id: 375, data: {type: text, data: {text: b3}}, conversation_id: m_iUuuVitsngrL4oRDvz7V3k6MoMJwaz_uVqGmpI3rBU_Pe_4zwKGNL4mH2LKJM1S_OLTSzBvNu-k5Y9w47sdu2g, timestamp: 1671283144708, admin_id: 256, admin_info: {id: 256, email: masuma+1@myalice.ai, avatar: https://s3-ap-southeast-1.amazonaws.com/stage-alice-v3/misc/7f2bdade109811ecabd40242c0a82005.jpeg, full_name: Masuma Imu}, success: null, pusher_key: 98d0990d74984ab2be8a047f62cd43c9}}

sakibguy commented 1 year ago

Received value on sendConvText()

I/flutter (14212): [---ok---] sendConvText(): 1

{success: true, dataSource: {_id: null, type: message, source: admin, platform_type: facebook_messenger, platform_id: 1361, customer_id: 1043, project_id: 375, data: {type: text, data: {sub_type: null, urls: null, text: b6}}, conversation_id: m_iUuuVitsngrL4oRDvz7V3k6MoMJwaz_uVqGmpI3rBU_Pe_4zwKGNL4mH2LKJM1S_OLTSzBvNu-k5Y9w47sdu2g, timestamp: 1671286813177, admin_id: 256, admin_info: {id: 256, email: masuma+1@myalice.ai, avatar: https://s3-ap-southeast-1.amazonaws.com/stage-alice-v3/misc/7f2bdade109811ecabd40242c0a82005.jpeg, full_name: Masuma Imu}, success: null, pusher_key: ade1f14b049d4809be431544d45f7e83}}

SNaP

Screenshot (617)

sakibguy commented 1 year ago

Ignore now because https://github.com/sakibguy/worked-issues/issues/111#issuecomment-1356781365