package Ġco . nim ble hq . sms for warder . domain Ċ Ċ import Ġco . nim ble hq . sms for warder . data . service . error . Json ApiException Ċ import Ġco . nim ble hq . sms for warder . data . service . error . No Connectivity Exception Ċ import Ġco . nim ble hq . sms for warder . data . service . error . Unknown Exception Ċ import Ġco . nim ble hq . sms for warder . data . service . providers . M oshi Builder Provider Ċ import Ġco . nim ble hq . sms for warder . data . service . response . ErrorResponse Ċ import Ġio . reactivex . Single Ċ import Ġretrofit 2 . Response Ċ import Ġjava . io . Inter rupted IOException Ċ import Ġjava . net . Socket TimeoutException Ċ import Ġjava . net . Unknown Host Exception Ċ Ċ fun Ġ< T > ĠSingle < Response < T >> . transform (): ĠSingle < T > Ġ= Ġflat Map Ġ{ ĊĠĠĠ Ġval Ġbody Ġ= Ġit . body () ĊĠĠĠ Ġif Ġ( it . is Successful Ġ&& Ġbody Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠ ĠSingle . just ( body ) ĊĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠ ĠSingle . error ( map Error ( it )) ĊĠĠĠ Ġ} Ċ }. onError Resume Next Ġ{ ĊĠĠĠ Ġwhen Ġ( it ) Ġ{ ĊĠĠĠĠĠĠĠ Ġis ĠSocket TimeoutException Ġ-> ĠSingle . error ( it ) ĊĠĠĠĠĠĠĠ Ġis ĠUnknown Host Exception , ĊĠĠĠĠĠĠĠ Ġis ĠInter rupted IOException Ġ-> ĠSingle . error ( No Connectivity Exception ) ĊĠĠĠĠĠĠĠ Ġelse Ġ-> ĠSingle . error ( it ) ĊĠĠĠ Ġ} Ċ } Ċ Ċ private Ġfun Ġ< T > Ġmap Error ( response : ĠResponse < T >? ): ĠException Ġ{ ĊĠĠĠ Ġval Ġerror Body Ġ= Ġresponse ?. error Body ()?. string () ĊĠĠĠ Ġval Ġerror Response Ġ= Ġparse ErrorResponse ( error Body ) ĊĊĠĠĠ Ġreturn Ġif Ġ( error Response Ġ!= Ġnull Ġ&& Ġresponse Ġ!= Ġnull ) ĠJson ApiException ( error Response , Ġresponse ) ĊĠĠĠ Ġelse ĠUnknown Exception Ċ } Ċ Ċ private Ġfun Ġparse ErrorResponse ( source : ĠString ?): ĠError Response ? Ġ{ ĊĠĠĠ Ġreturn Ġtry Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġm oshi Ġ= ĠM oshi Builder Provider . mos hi Builder . build () ĊĠĠĠĠĠĠĠ Ġval Ġadapter Ġ= Ġm oshi . adapter ( ErrorResponse :: class . java ) ĊĠĠĠĠĠĠĠ Ġadapter . fromJson ( source . or Empty ()) ĊĠĠĠ Ġ} Ġcatch Ġ( e : ĠException ) Ġ{ ĊĠĠĠĠĠĠĠ Ġnull ĊĠĠĠ Ġ} Ċ } Ċ