11package com .rtm516 .mcxboxbroadcast .core ;
22
33import com .github .mizosoft .methanol .Methanol ;
4+ import com .google .gson .JsonParseException ;
45import com .rtm516 .mcxboxbroadcast .core .exceptions .SessionCreationException ;
56import com .rtm516 .mcxboxbroadcast .core .exceptions .SessionUpdateException ;
67import com .rtm516 .mcxboxbroadcast .core .models .session .CreateHandleRequest ;
@@ -200,13 +201,18 @@ private void createSession() throws SessionCreationException, SessionUpdateExcep
200201 );
201202
202203 // Make the request to create the session handle
203- HttpRequest createHandleRequest = HttpRequest .newBuilder ()
204- .uri (Constants .CREATE_HANDLE )
205- .header ("Content-Type" , "application/json" )
206- .header ("Authorization" , token )
207- .header ("x-xbl-contract-version" , "107" )
208- .POST (HttpRequest .BodyPublishers .ofString (Constants .GSON .toJson (createHandleContent )))
209- .build ();
204+ HttpRequest createHandleRequest ;
205+ try {
206+ createHandleRequest = HttpRequest .newBuilder ()
207+ .uri (Constants .CREATE_HANDLE )
208+ .header ("Content-Type" , "application/json" )
209+ .header ("Authorization" , token )
210+ .header ("x-xbl-contract-version" , "107" )
211+ .POST (HttpRequest .BodyPublishers .ofString (Constants .GSON .toJson (createHandleContent )))
212+ .build ();
213+ } catch (JsonParseException e ) {
214+ throw new SessionCreationException ("Unable to create session handle, error parsing json: " + e .getMessage ());
215+ }
210216
211217 // Read the handle response
212218 HttpResponse <String > createHandleResponse ;
@@ -216,7 +222,7 @@ private void createSession() throws SessionCreationException, SessionUpdateExcep
216222 CreateHandleResponse parsedResponse = Constants .GSON .fromJson (createHandleResponse .body (), CreateHandleResponse .class );
217223 sessionInfo .setHandleId (parsedResponse .id ());
218224 }
219- } catch (IOException | InterruptedException e ) {
225+ } catch (JsonParseException | IOException | InterruptedException e ) {
220226 throw new SessionCreationException (e .getMessage ());
221227 }
222228
@@ -245,13 +251,18 @@ private void createSession() throws SessionCreationException, SessionUpdateExcep
245251 * @throws SessionUpdateException If the update fails
246252 */
247253 protected String updateSessionInternal (String url , Object data ) throws SessionUpdateException {
248- HttpRequest createSessionRequest = HttpRequest .newBuilder ()
249- .uri (URI .create (url ))
250- .header ("Content-Type" , "application/json" )
251- .header ("Authorization" , getTokenHeader ())
252- .header ("x-xbl-contract-version" , "107" )
253- .PUT (HttpRequest .BodyPublishers .ofString (Constants .GSON .toJson (data )))
254- .build ();
254+ HttpRequest createSessionRequest ;
255+ try {
256+ createSessionRequest = HttpRequest .newBuilder ()
257+ .uri (URI .create (url ))
258+ .header ("Content-Type" , "application/json" )
259+ .header ("Authorization" , getTokenHeader ())
260+ .header ("x-xbl-contract-version" , "107" )
261+ .PUT (HttpRequest .BodyPublishers .ofString (Constants .GSON .toJson (data )))
262+ .build ();
263+ } catch (JsonParseException e ) {
264+ throw new SessionUpdateException ("Unable to update session information, error parsing json: " + e .getMessage ());
265+ }
255266
256267 HttpResponse <String > createSessionResponse ;
257268 try {
@@ -382,7 +393,7 @@ public SocialSummaryResponse socialSummary() {
382393
383394 try {
384395 return Constants .GSON .fromJson (httpClient .send (socialSummaryRequest , HttpResponse .BodyHandlers .ofString ()).body (), SocialSummaryResponse .class );
385- } catch (IOException | InterruptedException e ) {
396+ } catch (JsonParseException | IOException | InterruptedException e ) {
386397 logger .error ("Unable to get current friend count" , e );
387398 }
388399
0 commit comments