2016-10-26 5 views
0

안녕하세요 여러분, 저는 서버에서 실제 자세한 오류 메시지를 읽는 방법을 모르지만 E/Volley : [73767] BasicNetwork.performRequest : 예기치 않은 응답 코드 500 https://xxxx.com/xxxxx 나는 사람들이 onErrorResponse 리스너를 추가하는 것을 보았습니다.하지만 제 생각에는 명확하게 뭔가 빠져 있습니다. 아래 코드는 제게 도움이되었습니다.Volley 읽는 방법 예기치 않은 응답 코드 500

요청 :

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; 
    } 
} 
+0

발리 대신에 개조를 사용해야합니다. – Nenco

+0

오! 나는 그것이 정말로 대중적이었던 것처럼 보였기 때문에 원인을 사용했다. 나는 그 모든 것에 대해 무엇을보기 위해 개장을 연구 할 것이다 :), 제안에 감사드립니다! – rapid3642

답변

1

나는 ErrorListener를에 GetUserFavoritesRequest의 생성자

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

변경 널 (null)에서 실수가있을 수 있습니다 생각합니다.

+0

OMG 예 완벽! 고맙습니다! 나는 생성자에 대해 잘 모르겠다. 그래서 이것은 아주 좋은 캐치였다. 나는 올바른 방향으로 나아가고 있지만 여전히 전체 오류 메시지를 읽을 수는 없습니다. 여기 내가 얻는 것이 있습니다. 이메일/발리 : [83012] BasicNetwork.performRequest : https://xxxx.com/xxxxx 예기치 않은 응답 코드 E/Volley : Error. HTTP 상태 코드 : 500 전자/발리 : ServerError D/Maps :: 오류 : null – rapid3642

+1

시도하십시오 Log.d ("지도 :", "오류 :"+ 새 문자열 (error.networkResponse.data)); finished = true; –

+0

롤 예! 다시 올바른 방향으로 움직입니다! 나는 상세한 메시지의 결과물을 얻을 수는 있지만 어떤 이유 때문에 모든 것을 표시하지는 못한다. 그것의 너무 많은 데이터 또는 뭔가의 원인을 잘라 점점 좋아. 전체 메시지가 인쇄되지 않는 이유를 알고 있습니까? 내가 모질라 REST 클라이언트를 사용하여 오류를 돕는 원인이 전체 메시지가 아니라는 것을 알 수있는 유일한 이유가 있지만, 궁극적 인 목표는 내 애플리케이션이 모든 로깅을 처리하고 유용한 디버깅 정보를 생성하도록하는 것입니다. – rapid3642

관련 문제