0

Hi guys I do not know how to read the actual detailed error message from the server, all I am getting is E/Volley: [73767] BasicNetwork.performRequest: Unexpected response code 500 for https://xxxx.com/xxxxx I saw people adding a onErrorResponse listener but mine isnt working so im clearly missing something, below is my code, any help is appreciated.

Request:

JSONObject jsonFavorites = new JSONObject();
                        String userId = Integer.toString(2);
                        String waypointID = Integer.toString(eventInfo.waypointId);
                        String waypointType = Integer.toString(eventInfo.stopType);
                        try {
                            jsonFavorites.put("action", favoriteAction);
                            jsonFavorites.put("uid", userId);
                            jsonFavorites.put("waypointid", waypointID);
                            jsonFavorites.put("waypoint_type", waypointType);
                            //fetchData(bounds);
                        } catch (Exception e) {

                        }
                        try{
                            GetUserFavoritesRequest favoritesRequest = new GetUserFavoritesRequest(jsonFavorites, new Response.Listener<String>() {
                                @Override
                                public void onResponse(String response) {
                                    //Parse the response that was received from the server.
                                    Log.d("Maps:", " Parsing Response");
                                    try {
                                        Log.i("tagconvertstr", "[" + response + "]");
                                        //List<String> allFavorites = new ArrayList<String>();

                                        JSONArray cast = new JSONArray(response);

                                        if(userFavoritewaypointId.contains(eventInfo.waypointId)){
                                            favoriteAction = "remove";
                                            infoFavoriteButton.setImageResource(R.drawable.favorites_disabled);
                                        }else{
                                            favoriteAction = "add";
                                            infoFavoriteButton.setImageResource(R.drawable.favorites);
                                        }
                                        finished = true;
                                    } catch (JSONException e) {
                                        //adding or removing favorites was unsuccessful.
                                        Log.d("Maps:", " Failed getting a response from server for adding or removing favorites");
                                        e.printStackTrace();

                                        //Set the finished flag to true to let everyone know that we
                                        //finished receiving a response from the server.
                                        finished = true;
                                    }
                                }
                            }, new Response.ErrorListener() {
                                @Override
                                public void onErrorResponse(VolleyError error) {
                                    //Parse the response that was received from the server.
                                    NetworkResponse networkResponse = error.networkResponse;
                                    if (networkResponse != null) {
                                        Log.e("Volley", "Error. HTTP Status Code:"+networkResponse.statusCode);
                                    }

                                    if (error instanceof TimeoutError) {
                                        Log.e("Volley", "TimeoutError");
                                    }else if(error instanceof NoConnectionError){
                                        Log.e("Volley", "NoConnectionError");
                                    } else if (error instanceof AuthFailureError) {
                                        Log.e("Volley", "AuthFailureError");
                                    } else if (error instanceof ServerError) {
                                        Log.e("Volley", "ServerError");
                                    } else if (error instanceof NetworkError) {
                                        Log.e("Volley", "NetworkError");
                                    } else if (error instanceof ParseError) {
                                        Log.e("Volley", "ParseError");
                                    }
                                    Log.d("Maps:", " Error: " + error.getMessage());
                                    finished = true;
                                }
                            });
                            RequestQueue queue = Volley.newRequestQueue(getActivity());
                            queue.add(favoritesRequest);

                        } catch (Exception e) {
                            //We failed to start a login request.
                            Log.d("Maps:", " Failed to start response for adding or removing favorites");

                            //Set the finished flag to true to let everyone know that we
                            //finished receiving a response from the server.
                            finished = true;
                        }

GetUserFavoritesRequest.java

public class GetUserFavoritesRequest extends StringRequest {
    private static final String LOGIN_REQUEST_URL = "https://xxxx.com/xxxxx";
    private Map<String, String> params;

    public GetUserFavoritesRequest(JSONObject getFavorites, Response.Listener<String> listener, Response.ErrorListener errorListener){
        super(Request.Method.POST, LOGIN_REQUEST_URL, listener, null);
        params = new HashMap<>();

        try {
            if(getFavorites.get("action").toString().equals("get")){
                Log.d("Maps: ", "Looks like we are retrieving a list of favorite waypoints");
                params.put("action", getFavorites.get("action").toString());
                params.put("uid", getFavorites.get("uid").toString());
            }else if(getFavorites.get("action").toString().equals("add")){
                Log.d("Maps: ", "Looks like we are adding a favorite waypoint" + getFavorites);
                params.put("action", getFavorites.get("action").toString());
                params.put("uid", getFavorites.get("uid").toString());
                params.put("waypointid", getFavorites.get("waypointid").toString());
                params.put("waypoint_type", getFavorites.get("waypoint_type").toString());
            }else if(getFavorites.get("action").toString().equals("remove")) {
                Log.d("Maps: ", "Looks like we are removing a favorite waypoint" + getFavorites);
                params.put("action", getFavorites.get("action").toString());
                params.put("uid", getFavorites.get("uid").toString());
                params.put("waypointid", getFavorites.get("waypointid").toString());
                params.put("waypoint_type", getFavorites.get("waypoint_type").toString());
            }
        }catch (Exception e){

        }
    }

    @Override
    public Map<String, String> getParams() {
        return params;
    }
}
rapid3642
  • 913
  • 2
  • 14
  • 26

1 Answers1

1

I think there might be a mistake in GetUserFavoritesRequest's constructor

super(Request.Method.POST, LOGIN_REQUEST_URL, listener, null);

change null to errorListener.

Charlie Wang
  • 136
  • 1
  • 4
  • OMG yes perfect!! Thank you! I am not knowledgeable about constructors so that was a very good catch. I am moving in the right direction however im still unable to read the full error message. Here is what I am getting. E/Volley: [83012] BasicNetwork.performRequest: Unexpected response code 500 for https://xxxx.com/xxxxx E/Volley: Error. HTTP Status Code:500 E/Volley: ServerError D/Maps:: Error: null – rapid3642 Oct 27 '16 at 18:14
  • 1
    try this Log.d("Maps:", " Error: " + new String(error.networkResponse.data)); finished = true; – Charlie Wang Oct 28 '16 at 01:22
  • lol yes!! again moving in the right direction! I am able to get some of the output of the detailed message but for some reason, it is not displaying all of it. its like its getting cut off cause of too much data or something. Do you know why the entire message is not being printed out? The only reason why I know its not the full message cause I was using Mozilla REST client to help me with the error, but the ultimate goal is to have my app handle all of the logging and producing useful debugging information. – rapid3642 Oct 28 '16 at 17:39
  • It seems log cat message had a length limitation, which is 4K. If your message is larger than it, please try to break it. ref : http://stackoverflow.com/questions/8888654/android-set-max-length-of-logcat-messages – Charlie Wang Oct 30 '16 at 15:48