@@ -54,7 +54,9 @@ private static <T> String convertToString(Class<T> cls, Object o) {
5454 */
5555 protected final RequestResponse requestGet (String token , String url ) {
5656 // Initialisation of http get request
57- HttpRequest request = new HttpRequest (BASE_URL + url , HttpMethod .GET );
57+ String requestURL = BASE_URL + url ;
58+ HttpMethod method = HttpMethod .GET ;
59+ HttpRequest request = new HttpRequest (requestURL , method );
5860 request .addRequestHeader ("Authorization" , "Bearer " + token );
5961 request .addRequestHeader ("Content-Type" , "application/json" );
6062
@@ -63,26 +65,24 @@ protected final RequestResponse requestGet(String token, String url) {
6365 HttpResponse response = request .execute ();
6466 int code = response .getCode ();
6567 String s = response .getMessage ();
68+ JSONObject content = null ;
6669 switch (code ) {
67- case 200 :
68- return new RequestResponse (new JSONObject (response .getContent ()), code , s );
69- case 401 :
70- System .out .println ("Bad or expired token. This can happen if the user revoked a " +
71- "token or the access token has expired. You should re-authenticate the user." );
72- case 403 :
73- System .out .println ("Bad OAuth request (wrong consumer key, bad nonce, expired timestamp...)" +
74- ". Unfortunately, re-authenticating the user won't help here." );
75- case 429 :
76- System .out .println ("The app has exceeded its rate limits." );
77- case 400 :
78- System .out .println ("Bad request." );
79- case 404 :
80- System .out .println ("Unknown request" );
81- default :
82- System .out .printf ("Unknown fail cause, status code: %s.%n" , code );
70+ case 200 -> content = new JSONObject (response .getContent ());
71+ case 401 -> System .out .printf ("Error: Bad or expired token. This can happen if the user revoked a " +
72+ "token or the access token has expired. You should re-authenticate the user for %s request %s%n" ,
73+ method , requestURL );
74+ case 403 ->
75+ System .out .printf ("Error: Bad OAuth request (wrong consumer key, bad nonce, expired timestamp...)" +
76+ ". Unfortunately, re-authenticating the user won't help here for %s request %s.%n" , method ,
77+ requestURL );
78+ case 429 -> System .out .println ("Error: The app has exceeded its rate limits." );
79+ case 400 -> System .out .printf ("Error: Bad request for %s request %s%n" , method , requestURL );
80+ case 404 -> System .out .printf ("Error: Unknown request for %s request %s%n" , method , requestURL );
81+ default -> System .out .printf ("Error: Unknown fail cause, status code: '%s' for %s request %s .%n" , code ,
82+ method , requestURL );
8383 }
8484
85- return new RequestResponse (null , code , s );
85+ return new RequestResponse (content , code , s );
8686
8787
8888 } catch (NullPointerException e ) {
0 commit comments