@@ -45,7 +45,7 @@ public final Output sync() throws PubnubException {
4545 try {
4646 serverResponse = call .execute ();
4747 } catch (IOException e ) {
48- throw new PubnubException ( PubnubError .PNERROBJ_HTTP_ERROR );
48+ throw PubnubException . builder (). pubnubError ( PubnubError .PNERROBJ_HTTP_ERROR ). build ( );
4949 }
5050
5151 if (!serverResponse .isSuccessful () || serverResponse .code () != 200 ) {
@@ -57,7 +57,11 @@ public final Output sync() throws PubnubException {
5757 responseBodyText = "N/A" ;
5858 }
5959
60- throw new PubnubException (PubnubError .PNERROBJ_HTTP_ERROR , responseBodyText , serverResponse .code ());
60+ throw PubnubException .builder ()
61+ .pubnubError (PubnubError .PNERROBJ_HTTP_ERROR )
62+ .errormsg (responseBodyText )
63+ .statusCode (serverResponse .code ())
64+ .build ();
6165 }
6266
6367 response = createResponse (serverResponse );
@@ -72,7 +76,12 @@ public final Call<Input> async(final PNCallback<Output> callback) {
7276 try {
7377 call = doWork (createBaseParams ());
7478 } catch (PubnubException e ) {
75- PubnubException pubnubException = new PubnubException (PubnubError .PNERROBJ_INVALID_ARGUMENTS , e .getMessage ());
79+
80+ PubnubException pubnubException = PubnubException .builder ()
81+ .pubnubError (PubnubError .PNERROBJ_INVALID_ARGUMENTS )
82+ .errormsg (e .getMessage ())
83+ .build ();
84+
7685 PNErrorStatus pnErrorStatus = new PNErrorStatus ();
7786 writeFieldsToResponse (null , pnErrorStatus , true , pubnubException );
7887 callback .onResponse (null , pnErrorStatus );
@@ -96,7 +105,12 @@ public void onResponse(final Call<Input> call, final Response<Input> response) {
96105 responseBodyText = "N/A" ;
97106 }
98107
99- PubnubException ex = new PubnubException (PubnubError .PNERROBJ_HTTP_ERROR , responseBodyText , response .code ());
108+ PubnubException ex = PubnubException .builder ()
109+ .pubnubError (PubnubError .PNERROBJ_HTTP_ERROR )
110+ .errormsg (responseBodyText )
111+ .statusCode (response .code ())
112+ .build ();
113+
100114 writeFieldsToResponse (response , pnErrorStatus , true , ex );
101115 callback .onResponse (null , pnErrorStatus );
102116 return ;
@@ -105,7 +119,13 @@ public void onResponse(final Call<Input> call, final Response<Input> response) {
105119 try {
106120 callbackResponse = createResponse (response );
107121 } catch (PubnubException e ) {
108- PubnubException pubnubException = new PubnubException (PubnubError .PNERROBJ_HTTP_ERROR , e .getMessage (), response .code ());
122+
123+ PubnubException pubnubException = PubnubException .builder ()
124+ .pubnubError (PubnubError .PNERROBJ_HTTP_ERROR )
125+ .errormsg (e .getMessage ())
126+ .statusCode (response .code ())
127+ .build ();
128+
109129 writeFieldsToResponse (response , pnErrorStatus , true , pubnubException );
110130 callback .onResponse (null , pnErrorStatus );
111131 return ;
@@ -118,7 +138,12 @@ public void onResponse(final Call<Input> call, final Response<Input> response) {
118138 @ Override
119139 public void onFailure (final Call <Input > call , final Throwable throwable ) {
120140 PNErrorStatus pnErrorStatus = new PNErrorStatus ();
121- PubnubException pubnubException = new PubnubException (PubnubError .PNERROBJ_HTTP_ERROR , throwable .getMessage (), null );
141+
142+ PubnubException pubnubException = PubnubException .builder ()
143+ .pubnubError (PubnubError .PNERROBJ_HTTP_ERROR )
144+ .errormsg (throwable .getMessage ())
145+ .build ();
146+
122147 writeFieldsToResponse (null , pnErrorStatus , true , pubnubException );
123148 callback .onResponse (null , pnErrorStatus );
124149
@@ -152,19 +177,19 @@ protected String signSHA256(String key, String data) throws PubnubException {
152177 try {
153178 sha256_HMAC = Mac .getInstance ("HmacSHA256" );
154179 } catch (NoSuchAlgorithmException e ) {
155- throw new PubnubException ( PubnubError .PNERROBJ_CRYPTO_ERROR , e .getMessage (), null );
180+ throw PubnubException . builder (). pubnubError ( PubnubError .PNERROBJ_CRYPTO_ERROR ). errormsg ( e .getMessage ()). build ( );
156181 }
157182
158183 try {
159184 sha256_HMAC .init (secretKey );
160185 } catch (InvalidKeyException e ) {
161- throw new PubnubException ( PubnubError .PNERROBJ_CRYPTO_ERROR , e .getMessage (), null );
186+ throw PubnubException . builder (). pubnubError ( PubnubError .PNERROBJ_CRYPTO_ERROR ). errormsg ( e .getMessage ()). build ( );
162187 }
163188
164189 try {
165190 hmacData = sha256_HMAC .doFinal (data .getBytes ("UTF-8" ));
166191 } catch (UnsupportedEncodingException e ) {
167- throw new PubnubException ( PubnubError .PNERROBJ_CRYPTO_ERROR , e .getMessage (), null );
192+ throw PubnubException . builder (). pubnubError ( PubnubError .PNERROBJ_CRYPTO_ERROR ). errormsg ( e .getMessage ()). build ( );
168193 }
169194
170195 return new String (Base64 .encode (hmacData , 0 )).replace ('+' , '-' ).replace ('/' , '_' );
0 commit comments