@ -8,6 +8,7 @@ import 'package:doctor_app_flutter/core/model/patient/patiant_info_model.dart';
import ' package:doctor_app_flutter/core/service/NavigationService.dart ' ;
import ' package:doctor_app_flutter/core/viewModel/authentication_view_model.dart ' ;
import ' package:doctor_app_flutter/utils/dr_app_shared_pref.dart ' ;
import ' package:doctor_app_flutter/utils/exception_report.dart ' ;
import ' package:doctor_app_flutter/utils/utils.dart ' ;
import ' package:flutter/cupertino.dart ' ;
import ' package:http/http.dart ' as http ;
@ -130,6 +131,8 @@ class BaseAppClient {
final int statusCode = response . statusCode ;
if ( statusCode < 200 | | statusCode > = 400 ) {
onFailure ( Utils . generateContactAdminMsg ( ) , statusCode ) ;
if ( body [ ' DoctorID ' ] ! = null )
postFailureResponse ( doctorId: body [ ' DoctorID ' ] , url: url , request: json . encode ( body ) , response: response . body , exception: " $ statusCode " ) ;
} else {
var parsed = json . decode ( response . body . toString ( ) ) ;
if ( parsed [ ' ErrorType ' ] = = 4 ) {
@ -141,11 +144,13 @@ class BaseAppClient {
if ( parsed [ ' ErrorCode ' ] = = ' 699 ' ) {
onSuccess ( parsed , statusCode ) ;
} else {
if ( body [ ' DoctorID ' ] ! = null )
postFailureResponse ( doctorId: body [ ' DoctorID ' ] , url: url , request: json . encode ( body ) , response: response . body , exception: getError ( parsed ) ) ;
onFailure ( getError ( parsed ) , statusCode ) ;
}
} else if ( ! isAllowAny ) {
await Provider . of < AuthenticationViewModel > ( AppGlobal . CONTEX , listen: false ) . logout ( ) ;
/ / todo nofailure is placed here and but have to handle the response here as well
Utils . showErrorToast ( ' Your session expired Please login again ' ) ;
locator < NavigationService > ( ) . pushNamedAndRemoveUntil ( ROOT ) ;
}
@ -153,11 +158,15 @@ class BaseAppClient {
onFailure ( getError ( parsed ) , statusCode ) ;
}
} else if ( parsed [ ' MessageStatus ' ] = = 1 ) {
if ( ! parsed [ ' IsAuthenticated ' ] )
if ( ! parsed [ ' IsAuthenticated ' ] ) {
if ( body [ ' DoctorID ' ] ! = null )
postFailureResponse ( doctorId: body [ ' DoctorID ' ] , url: url , request: json . encode ( body ) , response: response . body , exception: getError ( parsed ) ) ;
onFailure ( getError ( parsed ) , statusCode ) ;
else
} else
onSuccess ( parsed , statusCode ) ;
} else {
if ( body [ ' DoctorID ' ] ! = null )
postFailureResponse ( doctorId: body [ ' DoctorID ' ] , url: url , request: json . encode ( body ) , response: response . body , exception: getError ( parsed ) ) ;
onFailure ( getError ( parsed ) , statusCode ) ;
}
}
@ -291,6 +300,8 @@ class BaseAppClient {
if ( parsed ! = null ) {
onSuccess ( parsed , statusCode ) ;
} else {
if ( body [ ' DoctorID ' ] ! = null )
postFailureResponse ( doctorId: body [ ' DoctorID ' ] , url: url , request: json . encode ( body ) , response: response . body , exception: getError ( parsed ) ) ;
onFailure ( getError ( parsed ) , statusCode ) ;
}
}
@ -302,11 +313,18 @@ class BaseAppClient {
} else {
if ( parsed [ ' message ' ] = = null & & parsed [ ' ErrorEndUserMessage ' ] = = null ) {
if ( parsed [ ' ErrorSearchMsg ' ] = = null ) {
if ( body [ ' DoctorID ' ] ! = null )
postFailureResponse ( doctorId: body [ ' DoctorID ' ] , url: url , request: json . encode ( body ) , response: response . body , exception: " Server Error found with no available message " ) ;
onFailure ( " Server Error found with no available message " , statusCode ) ;
} else {
if ( body [ ' DoctorID ' ] ! = null )
postFailureResponse ( doctorId: body [ ' DoctorID ' ] , url: url , request: json . encode ( body ) , response: response . body , exception: parsed [ ' ErrorSearchMsg ' ] ) ;
onFailure ( parsed [ ' ErrorSearchMsg ' ] , statusCode ) ;
}
} else {
if ( body [ ' DoctorID ' ] ! = null )
postFailureResponse ( doctorId: body [ ' DoctorID ' ] , url: url , request: json . encode ( body ) , response: response . body , exception: parsed [ ' message ' ] ? ? parsed [ ' ErrorEndUserMessage ' ] ? ? parsed [ ' ErrorMessage ' ] ) ;
onFailure ( parsed [ ' message ' ] ? ? parsed [ ' ErrorEndUserMessage ' ] ? ? parsed [ ' ErrorMessage ' ] , statusCode ) ;
}
}
@ -315,8 +333,14 @@ class BaseAppClient {
onSuccess ( parsed , statusCode ) ;
} else {
if ( parsed [ ' message ' ] ! = null ) {
if ( body [ ' DoctorID ' ] ! = null )
postFailureResponse ( doctorId: body [ ' DoctorID ' ] , url: url , request: json . encode ( body ) , response: response . body , exception: parsed [ ' message ' ] ) ;
onFailure ( parsed [ ' message ' ] ? ? parsed [ ' message ' ] , statusCode ) ;
} else {
if ( body [ ' DoctorID ' ] ! = null )
postFailureResponse ( doctorId: body [ ' DoctorID ' ] , url: url , request: json . encode ( body ) , response: response . body , exception: parsed [ ' ErrorEndUserMessage ' ] ? ? parsed [ ' ErrorMessage ' ] ) ;
onFailure ( parsed [ ' ErrorEndUserMessage ' ] ? ? parsed [ ' ErrorMessage ' ] , statusCode ) ;
}
}