Как отладить залп ошибки 500 из PHP (Yii2) исключение? - PullRequest
0 голосов
/ 07 сентября 2018

Функция в Chrome возвращает действительный JSON, а в PostMan также, как показано ниже:

{"name":"Not Found","message":"Page not found.","code":0,"status":404,"type":"yii\\web\\NotFoundHttpException","previous":{"name":"Invalid Route","message":"Unable to resolve the request: api/v1/visitor/x","code":0,"type":"yii\\base\\InvalidRouteException"}}

Java-код:

final JSONObject json = new JSONObject();
    final TextView visitorMobile = findViewById(R.id.visitor_mobile);
    final String url = getResources().getString(R.string.url_search_mobile);
    final String urlP = url+mobileInput;

    /*try {
        //json.put("mobile", visitorMobile.getText());
        json.put("Content-Type","application/json");
    } catch (JSONException e) {
        e.printStackTrace();
    }*/

    Log.d(TAG, "numbersList: "+ urlP);

    visitorMobile.onEditorAction(EditorInfo.IME_ACTION_DONE); // hide the keyboard
    final ProgressDialog dialog = ProgressDialog.show(this, null, "Please Wait"); //loading dialog


    final JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, urlP, null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    Log.d(TAG, response.toString());
                    dialog.dismiss();
                    try {
                        int status = response.getInt("status");
                        String message = response.getString("message");
                        if(status == 400) {
                            WebServiceUtils.showDialog(VisitorForm.this, "Error" ,message);
                        }else if(status == 201){
                            WebServiceUtils.showDialog(VisitorForm.this, "Success" ,message);
                            //Intent SendOtpActivity = new Intent(SendMobileActivity.this, SendOtpActivity.class);
                            //startActivity(SendOtpActivity);

                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }

Код PHP:

    public function actionMobile ($mobile) {
    $search = Visitor::findByMobile($mobile);

    throw new \yii\base\Exception() ; //for testing only
    if($search){
        return ["result"=>$search];
        return \Yii::$app->response->data = ['status' => '200', 'result' => $search];
    }
    \Yii::$app->response->data = ['status' => '401', 'message' => 'Not Found!'];

}

Ошибка в Android Studio E/Volley: [1413] BasicNetwork.performRequest: Unexpected response code 500 for http://localhost/api/v1/visitor/mobile/165

Результат ответа ошибки залпа:

D/VisitorForm: ERRORS
           ERROR: com.android.volley.ServerError
           MESSAGE: null
           CAUSE: null
D/VisitorForm: HEADERS: [Header[name=Connection,value=close], Header[name=Content-Type,value=application/json; charset=UTF-8], Header[name=Date,value=Thu, 06 Sep 2018 20:45:36 GMT], Header[name=Server,value=Apache/2.4.33 (Unix) PHP/7.2.8], Header[name=Transfer-Encoding,value=chunked], Header[name=X-Android-Received-Millis,value=1536266735555], Header[name=X-Android-Response-Source,value=NETWORK 500], Header[name=X-Android-Selected-Protocol,value=http/1.1], Header[name=X-Android-Sent-Millis,value=1536266735521], Header[name=X-Powered-By,value=PHP/7.2.8]]
           DATA: [B@b208d24
           STATUS: 500

Я надеюсь, что кто-то из облаков поможет с этим, потому что я не могу отобразить сообщение об ошибке в приложении.

...